带xml头的iPhone HTTPS帖子
我必须用一些XML数据发布HTTPS帖子,但我需要在HTTP头中发送XML 利用身体,我会做这样的事情带xml头的iPhone HTTPS帖子,iphone,post,https,Iphone,Post,Https,我必须用一些XML数据发布HTTPS帖子,但我需要在HTTP头中发送XML 利用身体,我会做这样的事情 request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:CACHE_POLICY timeoutInterval:TIMEOUT_INTERVAL]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
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];
<request>
<code1>666</code1 >
<code2>656</code2 >
<code3>767</code3 >
</request >
但这对标题不起作用,有人知道怎么做吗?
XML是这样的
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];
<request>
<code1>666</code1 >
<code2>656</code2 >
<code3>767</code3 >
</request >
谢谢。或者你的意思是在URL中,而不是在随机标题中?在一般情况下,HTTP头不用于将随机数据插入
[request setValue:@"<request><code1>666</code1 ><code2>656</code2 ><code3>767</code3 ></request >" forHTTPHeaderField:@"Your header field name?"];
恕我直言,我现在不想和我一起编译任何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];
你是对的,我试过了,但我的http头是错误的,这就是为什么我认为这不起作用。谢谢