2010-07-13 55 views
0

我必须用一些XML数据创建HTTPS帖子,但是我需要在HTTP标头中发送XML。带有xml标头的iPhone HTTPS帖子

使用身体,我会做这样的事情

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]; 

但是,这并不为头的工作,任何人都知道怎么做呢? XML是这样的

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

谢谢。

回答

0
[request setValue:@"<request><code1>666</code1 ><code2>656</code2 ><code3>767</code3 ></request >" forHTTPHeaderField:@"Your header field name?"]; 
+0

你说得对,我已经试过了,但我的HTTP标头是错误的这就是为什么我认为这不起作用。谢谢 – iDevZilla 2010-07-16 13:18:05

0

还是你的意思是“在URL中”,而不是随机的头?在一般情况下,HTTP标题不适用于将随机数据包入。

关闭我的头顶,但不尝试编译(与我无的Xcode现在),借口错别字:

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];