我使用的是AFNetworking 2.0,并且有一个AFHTTPRequestOperationManager子类HTTPClient,它处理应用程序中的所有HTTP流量。
我已经将HTTPClient的HTTPClient属性设置为[AFJSONRequestSerializer serializer],它应该用JSON对参数进行编码,并将它们放在请求体中。
这都是可行的,但是有些请求要求我将参数直接编码在它们的URL中,而不是默认的JSON格式。我考虑在自定义的requestSerializer上设置AFHTTPRequestOperation属性,但是这个类没有这样的属性。
TL;DR:有办法为每个HTTP设置requestSerializer属性吗?
发布于 2014-01-31 23:17:19
AFHTTPRequestOperation没有requestSerializer请求。我认为这种混淆的发生是因为您不正确地考虑对象创建的顺序。
如果您使用经理,会发生什么情况:
AFHTTPRequestOperation并将此请求分配给它。因此,如果您想使用不同的请求序列化程序来发出请求,这很简单:
/* 1. Make a NSMutableURLRequest using your own serializer */
NSMutableURLRequest *request = [myDifferentRequestSerializer requestWithMethod:@"GET" URLString:@"http://www.aol.com" parameters:parameters error:nil];
/* 2. Create an AFHTTPRequestOperation and assign this request to it. */
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperationManager sharedManager] HTTPRequestOperationWithRequest:request success:success failure:failure];
/* 3. Start the operation! */
[[AFHTTPRequestOperationManager sharedManager].operationQueue addOperation:operation];https://stackoverflow.com/questions/19768537
复制相似问题