簡體   English   中英

AFNetworking發布錯誤

[英]AFNetworking Post error

我正在嘗試發送POST請求,其中我有2個參數,然后將返回json對象。 我正在使用AFNetworking,每次都會收到此錯誤:

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請求

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腳本進行測試

    $var = $_POST["number"];
    $udid = $_POST["udid"];

     echo '{"match": 1}';

您的AFHTTPRequestOperationManager序列化程序需要json內容類型。 但是您的PHP同行將其回復為html。

在您的PHP中嘗試一下:

$var = $_POST["number"];
$udid = $_POST["udid"];

header('Content-Type: application/json');
echo '{"match": 1}';

另外,您可以將其他序列化程序設置為管理器並手動解析響應:

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM