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] => */*