无法读取POST参数

时间:2013-06-21 20:43:19

标签: php ios cocoa post afnetworking

我正在尝试使用AFNetworking将一些参数发送到API。我已将我的应用程序代码缩减为:

NSDictionary *params = @{@"team":@"WashingtonNationals"};

[_client postPath:@"updateTeamAlert"
       parameters:params
          success:^(AFHTTPRequestOperation *operation, id responseObject)
{
    NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
    NSLog(@"Request Successful, response '%@'", responseStr);
}
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
    NSLog(@"[HTTPClient Error]: %@", error.localizedDescription);
}];

在服务器上,我使用以下PHP进行调试:

if (isset($_POST["team"])) {
        echo "team  set ok";
    }
    else {
        echo "team not set";
    }

我一直收到'团队没有设定'的回应。

当我对POST进行vardump时,我会被退回:

'array(0) {

}

(我假设一个空数组?)

我错过了什么?

2 个答案:

答案 0 :(得分:0)

我不确定,但您可能遇到类似的问题:Read associative array from json in $_POST

如果是这种情况,您的数据可能在php://输入而不是$ _POST

答案 1 :(得分:0)

我错过了postPath中的尾随'/'。 :/

相关问题