我正在尝试将数据发布到成功连接的服务器,但不会获取我通过参数传递的数据。服务器设置为application/x-www-form-urlencoded
。我在这里查了一些例子,但没有看到它的修复。
我的参数如下所示:
parameter = @{@ "key1" : value1,
"key2" : value2};
我的方法就是这样:
- (void)postDataToServer:(NSDictionary*)parameters{
NSString *URLString = @"http://urlInfo";
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/x-www-form-urlencoded"];
[manager POST:URLString
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"responseObject: %@", responseObject);
NSLog(@"operation.responseString: %@",operation.responseString);
NSLog(@"operation.response: %@",operation.response);
}
failure:
^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
NSLog(@"Error Response --> %@",operation.responseString);
}];
}
我对成功案件的回应如下:
responseObject: <>
operation.responseString:
operation.response: <NSHTTPURLResponse: 0x37cd60> { URL: http://urlInfo } { status code: 200, headers {
"Content-Length" = 0;
Date = "Mon, 24 Nov 2014 03:06:22 GMT";
Server = "Apache-Coyote/1.1";
} }
有人可以指出这里缺少什么吗?谢谢。
答案 0 :(得分:0)
听起来像服务器问题,如果有问题的话。服务器返回200代码,通常表示成功。发布后,代码将POST主体发送为application/x-www-form-urlencoded
。除非您期望服务器回应响应数据,否则我不确定问题是什么......