ASIHTTPRequest addRequestHeader issue

我怕爱的太早我们不能终老 提交于 2019-12-11 13:39:44

问题


I am using ASIHttpRequest and make use GET method to send header to server. I call method addRequestHeader like this

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request addRequestHeader:@"myHeader" value:@"abc"];

It's not working. But if I use NSMutableURLRequest to add header and request to server, it works. I don't know anything wrong when calling addRequestHeader methods for ASIHTTPRequest library. Have anyone seen this issue?


回答1:


Wow ok so, yeah if this is a new app, please do NOT use ASIHttpRequest. It has long been supplanted by the delightful AFNetworking.

If this is an existing application, you really should work on a migration plan off ASI.

However, in an attempt to actually answer your question - that is the appropriate setup per the documentation, and is how I used to use it. My guess is something is broken under the covers and judging from a basic google request, there are issues with iOS 7 including memory leaks and requests just failing.




回答2:


You can do it via NSURLRequest

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.abc.com"]];
NSMutableURLRequest *mutableRequest = [request mutableCopy];
[mutableRequest addValue:@"AAA" forHTTPHeaderField:@"Hello-there"];
request = [mutableRequest copy];
NSLog(@"%@", request.allHTTPHeaderFields);

Hope this helps .. :)



来源:https://stackoverflow.com/questions/22827199/asihttprequest-addrequestheader-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!