大佬教程收集整理的这篇文章主要介绍了ios – AFNetworking 2.0 Domain = AFNetworkingErrorDomain Code = -1011“请求失败:内部服务器错误(500),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
+ (NSAFNetwokingrequestManager *)sharedClient { static NSAFNetwokingrequestManager *_sharedClient = nil; static dispatch_once_t onCEToken; dispatch_once(&onCEToken,^{ _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:GET_CAR_BRAND]]; }); return _sharedClient; } - (instanCETypE)initWithBaseURL:(NSURL *)url { self = [super initWithBaseURL:url]; if (self) { self.responseserializer = [AFXMLParserResponseserializer serializer]; self.responseserializer.acceptableContentTypes = [NSSet setWithObject:@"application/soap+xml"]; self.requestserializer = [AFhttprequestserializer serializer]; [self.requestserializer SETVALue:@"application/soap+xml" forhttpHeaderField:@"Content-type"]; } return self; } - (void)requestBrandcompletion:(NSAFNetwokingrequestManagerCompletionBlock)completion { NSString *soaprequest=@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLscheR_410_11845@a-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLscheR_410_11845@a\" xmlns:soap=\"http://scheR_410_11845@as.xmlsoap.org/soap/envelope/\">\n" "<soap:Body>\n" " <CarBrandExt xmlns=\"http://www.nohausystems.nl/\" />\n" "</soap:Body>\n" "</soap:Envelope>\n"; NSString *msgLength = [NSString StringWithFormat:@"%i",[soaprequest length]]; [self POST:GET_CAR_BRAND parameters:Nil construcTingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithHeaders:[NSDictionary DictionaryWithObjectsAndKeys:@"text/xml; charset=utf-8",@"Content-Type",msgLength,@"Content-Length",nil] body:[soaprequest dataUsingEncoding:NSUTF8StringEncoding]]; } success:^(AFhttprequestOperation *operation,id responSEObject) { if (completion) { completion(YES,responSEObject); } } failure:^(AFhttprequestOperation *operation,NSError *error) { if (completion) { completion(NO,nil); NSLog(@"Unable to fetch record error %@ with user info %@.",error,error.userInfo); } }]; }
我收到这个错误Domain = AFNetworkingErrorDomain Code = -1011“请求失败:内部服务器错误(500).任何人可以告诉我我在这里做错了什么?
得到这个回应:
{ status code: 500,headers { "Cache-Control" = private; "Content-Length" = 509; "Content-Type" = "application/soap+xml; charset=utf-8"; Date = "Thu,13 Mar 2014 12:59:45 GMT"; Server = "Microsoft-IIS/7.5"; "X-AspNet-Version" = "2.0.50727"; "X-Powered-By" = "ASP.NET"; } }
[self POST:GET_CAR_BRAND parameters:Nil construcTingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithHeaders:[NSDictionary DictionaryWithObjectsAndKeys:@"text/xml; charset=utf-8",nil] body:[soaprequest dataUsingEncoding:NSUTF8StringEncoding]];
它将content-type定义为“text / xml”,而服务器显然期待“application / soap xml”.您应该尝试将该部分代码更改为:
[self POST:GET_CAR_BRAND parameters:Nil construcTingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithHeaders:[NSDictionary DictionaryWithObjectsAndKeys:@"application/sopa+xml; charset=utf-8",nil] body:[soaprequest dataUsingEncoding:NSUTF8StringEncoding]];
更新建议:
尝试添加:
[self.requestserializer SETVALue:@"application/soap+xml; charset=utf-8" forhttpHeaderField:@"Content-Type"];
在你的 – (instanCETypE)initWithBaseURL:(NSURL *)url方法的最后.
如果这没有帮助,我建议做一些更详细的网络请求调试.你可以设置AFNetworkActivityLogger将请求/响应信息记录到控制台.
以上是大佬教程为你收集整理的ios – AFNetworking 2.0 Domain = AFNetworkingErrorDomain Code = -1011“请求失败:内部服务器错误(500)全部内容,希望文章能够帮你解决ios – AFNetworking 2.0 Domain = AFNetworkingErrorDomain Code = -1011“请求失败:内部服务器错误(500)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。