1

I am working in a iPhone project that uses restful web services. I need to send some tracking code or version number with every request sending from iPhone side. I am thinking of adding a header value into every request, by modifying a ASIHTTPRequest class.

  1. Is there any method that ASIHTTPRequest providing to do this (without modifying framework files)?
  2. If I need to modify ASIHTTPRequest class, what is the best place to modify it? (like buildRequestHeaders.. )

Thanks.

uiroshan
  • 5,021
  • 2
  • 39
  • 37

3 Answers3

4

You can add headers by following method

ASIFormDataRequest *currentRequest = [ASIFormDataRequest requestWithURL:url];
[currentRequest addRequestHeader:@""  value:@""];

e.g.[currentRequest addRequestHeader:@"Content-Type"  value:@"text/xml; charset=utf-8"];

Hope this helps.

Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
4

may be you can write a new class such as MyASIHttprequest and override the method requestwithURL

+ (MyASIHTTPrequest *) requestWithURL:url{
    MyASIHTTPrequest *request;
    if (request = [super requestWithUrl:url]){
        [request addRequestHeader:@""  value:@""];
    }
    return request;
}

or you can write a method to add the header but maybe every time you new a asihttprequest, you should call this method to add header;

Siverchen
  • 379
  • 2
  • 16
1

If you are just starting by adding in ASIHTTPRequest and it is not embedded into your app yet then I recommend that you stop and switch to something else.

The creator of ASIHTTPRequest has discontinued development on the framework and even recommends in his blog post "Honestly, I think now is the time to start looking elsewhere." -Blog post

Also this was addressed in this question as well: Is it safe to still use ASIHTTPRequest?

I would personally recommend that you use NSURLConnection and send the data through the POST method.

Community
  • 1
  • 1
Flipper
  • 2,589
  • 3
  • 24
  • 32