我第一次發送JSON到服務器,我不知道爲什麼我的PHP腳本沒有收到呼叫。從AFNetworking在PHP中恢復JSON
我認爲問題在於我如何從應用程序設置POST變量,我抓錯了一個或沒有按照預期設置$_POST['search']
。
任何人都可以指出我怎麼才能發佈數據,以及如何設置$_POST['search']
正確
我$var
回0
當我從Xcode的輸出看它。
PHP
header('Content-Type: text/json');
$var = (isset($_POST['search']) ? json_decode($_POST['search']) : false);
echo json_encode($var)
Objective-C的
NSDictionary *[email protected]{@"userID": @"1",
@"search":@{@"for":@"routine",
@"page":@"1",
@"orderBy":@"new",
@"type":@"1"}
};
NSURL *url = [[NSURL alloc]initWithString:@"http://192.168.1.64/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url];
httpClient.parameterEncoding = AFJSONParameterEncoding;
NSDictionary *params = myJson;
NSURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"http://192.168.1.64/igym/bootstrap.php" parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
NSLog(@"Inside the success block %@",JSON);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
NSLog(@"json text is: %@", JSON);
NSLog(@"Request failed with error: %@, %@", error, error.userInfo);
}];
[operation start];
你試過使用'$ _GET'嗎? – Undo
我應該將它作爲POST發送。得到的結果相同 –