1
votes

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?

2
Please, for the love of all that's good, DO NOT USE ASIHttpRequest. AFNetworking, NSURLSession, and goodness NSURLConnection all have modern APIs that will solve your problems without using an outdated and unsupported library like ASIHTTPRequest.Wayne Hartman

2 Answers

0
votes

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.

0
votes

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 .. :)