tags:

views:

137

answers:

2

Hi, I have to make a HTTPS Post with some XML data, but I need to send the XML in the HTTP header.

Using the body I would do something like this

request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:CACHE_POLICY timeoutInterval:TIMEOUT_INTERVAL];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
    [request setHTTPBody:postData];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

But this does not work for the header, anyone know how to make this? The XML is something like this

<request>
<code1>666</code1 >
<code2>656</code2 >
<code3>767</code3 >
</request >

Thanks.

A: 
[request setValue:@"<request><code1>666</code1 ><code2>656</code2 ><code3>767</code3 ></request >" forHTTPHeaderField:@"Your header field name?"];
Brad Smith
You're right, I've tried that, but my http header was wrong that's why I thought that this didn't work. Thanks
Boom
A: 

Or do you mean "in the URL", rather than a random header? HTTP Headers aren't for bunging random data into, in ordinary circumstances.

Off the top of my head, without trying to compile (no Xcode with me right now), excuse typos:

NSMutableString *urlString = [NSMutableString string];
[urlString append:@"http://wahtever.com?something=something"];
[urlString append:@"&data="];
[urlString append:[@"<request>...etc</request>" stringByAddingPercentEscapesUsingEncoding:UTF8StringEncoding];

NSURL *url = [NSURL URLwithString:urlString];
request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:CACHE_POLICY timeoutInterval:TIMEOUT_INTERVAL];
Adam