i'm trying to send a POST request where i have 2 parameters and then will get a json object back. I'm using AFNetworking and i get this error everytime:
Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo=0x16d93980 {com.alamofire.serialization.response.error.response= <NSHTTPURLResponse: 0x16d8f0d0> { URL: http://LINK } { status code: 404, headers {
Connection = "Keep-Alive";
"Content-Length" = 285;
"Content-Type" = "text/html; charset=iso-8859-1";
Date = "Fri, 11 Jul 2014 16:43:42 GMT";
"Keep-Alive" = "timeout=5, max=99";
Server = "Apache/2.4.9 (Ubuntu)";
} }, NSErrorFailingURLKey=http://LINK, NSLocalizedDescription=Request failed: not found (404), NSUnderlyingError=0x16d8f880 "Request failed: unacceptable content-type: text/html"}
POST Objective-c request
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"LINK"
parameters:@{@"number": storeID, @"udid" : [UIDevice currentDevice].identifierForVendor.UUIDString}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
NSLog(@"%@ = %@", storeID, [UIDevice currentDevice].identifierForVendor.UUIDString);
php script for testing
$var = $_POST["number"];
$udid = $_POST["udid"];
echo '{"match": 1}';
Your AFHTTPRequestOperationManager serializer expects a json content type. But your PHP peer responded it as html.
Try this in your PHP:
$var = $_POST["number"];
$udid = $_POST["udid"];
header('Content-Type: application/json');
echo '{"match": 1}';
Alternatively, you can set other serializer to your manager and parse the response manually:
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.