0

私のコードはここにあります:</p>

AFHTTPRequestOperationManager *managers = [AFHTTPRequestOperationManager manager];

NSMutableDictionary *parDic = [NSMutableDictionary dictionary];

[parDic setObject:@"admin" forKey:@"userId"];

[parDic setObject:@"1" forKey:@"password"];

  [managers POST:@"http://posttestserver.com/post.php?" parameters:par success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
    NSLog(@"sucess");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

次のように表示されます:<code>Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/plain"

しかし、このリクエストをキッチンでテストすると、問題なく動作します。

4

2 に答える 2

0

他のすべてを試した後、この行はうまくいきました:

operation.responseSerializer = [AFCompoundResponseSerializer シリアライザー];

NSString *strdata =[NSString stringWithFormat:@"{\"objID\":\"%ld\",\"objString\":\"%@\",\"objWidth\":\"%@\",\"objHeight\":\"%@\",\"objStartX\":\"%@\",\"objStartY\":\"%@\",\"objEndX\":\"%@\",\"objEndY\":\"%@\",\"objSnapX\":\"%@\",\"objSnapY\":\"%@\",\"objImage\":\"%@\"}",
                    (long)self.accelerometerObject.objID,
                    self.accelerometerObject.objString.string,
                    self.accelerometerObject.objWidth,
                    self.accelerometerObject.objHeight,
                    self.accelerometerObject.objStartX,
                    self.accelerometerObject.objStartY,
                    self.accelerometerObject.objEndX,
                    self.accelerometerObject.objEndY,
                    self.accelerometerObject.objSnapX,
                    self.accelerometerObject.objSnapY,
                    self.accelerometerObject.objImage];
NSLog(@"%@",strdata);
NSDictionary *parameters = @{
                             @"data" : strdata,
                             };
AFHTTPRequestOperationManager *requestOperationManager = [AFHTTPRequestOperationManager manager];
requestOperationManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
NSString *requestURL = @"http://yourserver.com/dataHandler.asmx/scriptToHandlePost";
requestOperationManager.responseSerializer = [AFCompoundResponseSerializer serializer];
requestOperationManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[requestOperationManager POST:requestURL
                   parameters:parameters
                      success:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     NSLog(@"Succeeded:    >>>>>>> %@",strdata);
 }
                      failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {
     NSLog(@">>>>>>>>>>>failed %@",error);
 }];
于 2014-08-12T12:41:48.407 に答える