- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我正在尝试使用子类 AFHTTPRequestOperationManager 将我的代码转换为 AFNetworking 2.0。这是我的代码
+ (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 "Request failed: internal server error (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", @"Content-Type", msgLength, @"Content-Length", nil] body:[soapRequest dataUsingEncoding:NSUTF8StringEncoding]];
将内容类型定义为“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", @"Content-Type", msgLength, @"Content-Length", 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 "请求失败 : internal server error (500),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22377776/
这是我用于从 web 服务获取 json 的代码 NSURL *url = [NSURL URLWithString:BaseURLString]; NSURLRequest *request
我向这样的 url 发送一个 GET 请求:https://test.com/app/login?json={"user":"test@gmail.com","password":"test " 但是
我正在使用 AFNetworking 进行 Web 服务。它在 NSURLConnection 上运行良好。使用 AFNetworking 时出现错误。 这是我的代码: AFHTTPSessionM
我在服务器 url 中有视频,然后我使用 AFNetworking 从 url 下载以便稍后播放视频。但是在下载时出现以下错误 Error Domain=AFNetworkingErrorDomain
我正在尝试使用子类 AFHTTPRequestOperationManager 将我的代码转换为 AFNetworking 2.0。这是我的代码 + (NSAFNetwokingRequestMana
我是一名优秀的程序员,十分优秀!