+ (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/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.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)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)