0

I am creating an iPhone http client that sends out 2 headers with its POST (or GET).

My server receives 7 headers.
The network library added 5 headers.

Is there a way to access the added headers from within the ios program?
or
Is there a way to suppress this feature and have it not add headers to the request?

I can already do this with external tools.
I just need the ios program to record all headers being sent out.

Here are all the ugly details:

code that sent the request from my iPhone:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];  

[request setValue:@"BlahAgent" forHTTPHeaderField:@"User-Agent"];
[request setValue:@"keep-alive" forHTTPHeaderField:@"Connection"];

NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];

NSLog(@"all headers %@",request.allHTTPHeaderFields);

this prints to xcode console:

all headers {
    Connection = "keep-alive";
    "User-Agent" = "BlahAgent";
}



on the receiving end (php) I run

$allHeaders = getallheaders();
print_r($allHeaders)

and get:

Array
(
    [Host] => 192.168.0.15
    [Accept-Encoding] => gzip, deflate
    [Accept] => */*
    [Accept-Language] => en-us
    [Connection] => keep-alive
    [Content-Length] => 0
    [User-Agent] => BlahAgent
)



I even did a wire shark and got:

POST /php/ajax.php HTTP/1.1
Host: 192.168.0.15
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en-us
Connection: keep-alive
Content-Length: 0
User-Agent: BlahAgent


I did it again but with GET and no headers and got:

[Host] => 192.168.0.15
[Connection] => keep-alive
[Accept-Encoding] => gzip, deflate
[User-Agent] => Blah%20Agent/1.0 CFNetwork/672.0.8 Darwin/14.0.0
[Accept-Language] => en-us
[Accept] => */*


godzilla
  • 971
  • 1
  • 10
  • 18
  • I didn't state it explicitly but I need to see the outgoing headers from within the program that is sending the request. I need progamatic access to the request headers that were added by the networking library. Sorry that I didn't make that clear. – godzilla Feb 11 '14 at 18:49

2 Answers2

0

Of course you can, try a web debugging tool such as: fiddler if you are runninng on windows, or charles if you have a mac. With any of those you can inspect the whole details of any request being sent, given that he stands as a proxy for every connection sent through http.

EDIT: Also, note that the remaining headers you are not setting are automatically given by the HTTP protocol, since they are required in a transaction.

Daniel Conde Marin
  • 7,588
  • 4
  • 35
  • 44
  • I can already read the request headers externally but I need to read them from the app that is making the request. I did a telnet session and the only header needed was host: thanks for the input anyway. I'm sure that ios has a way to read the outgoing headers that were added, I just don't know how. – godzilla Feb 11 '14 at 08:10
0

Its looking like what I want can't be done.
discussed here

You can setup a local server send the request to it and have it send back the full request,
but that is sort of Rube Goldburg-ish.
or
You can problably use a lower level library without the magic elves doing stuff for you.

Community
  • 1
  • 1
godzilla
  • 971
  • 1
  • 10
  • 18