gpt4 book ai didi

java - AFNetworking 在 Java Web 服务中失败

转载 作者:行者123 更新时间:2023-12-01 13:35:52 25 4
gpt4 key购买 nike

NSURL *url = [NSURL here`URLWithString:@"http://testing.appspot.com/json/ListingBusinessService/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

httpClient.parameterEncoding = AFJSONParameterEncoding;

NSDictionary *params = @{@"params":@"women",@"params" : @"women", @"params":@"women"};

[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];

[httpClient
postPath:@"getNewArrivalProductDetailsWithPaginationForIosApp"
parameters:params
success:^(AFHTTPRequestOperation *operation,id responseObject)
{
NSLog(@"%@",responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"%@",error);
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Data"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
}
];

我在执行上面的代码(如 AFNetworkingOperationFailingURLRequestErrorKey )时遇到以下错误,我想我在参数中遗漏了一些内容,请在此提出建议,提前致谢。

最佳答案

从命令行使用curl调用此URL后,我想说问题是响应内容类型是text/plain而不是application/json。 AFJSONRequestOperation 需要 application/json ContentType。

< HTTP/1.1 200 OK
< X-TraceUrl: /appstats/details?time=1390399595248&type=json
< Content-Type: text/plain; charset=UTF-8
< Accept-Ranges: bytes
< Vary: Accept-Encoding
< Date: Wed, 22 Jan 2014 14:06:35 GMT
* Server Google Frontend is not blacklisted
< Server: Google Frontend
< Cache-Control: private
< Alternate-Protocol: 80:quic
< Transfer-Encoding: chunked

关于java - AFNetworking 在 Java Web 服务中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21284557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com