我正在编写iPhone应用程序,我需要安全地发送XML请求并安全地接收它。我想我做得对,我只想要确认下面的代码都是安全的。感谢。
NSURL *url = [NSURL URLWithString: @"https://secure.site.com/request"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [xml length]];
[req addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [xml dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 如果(连环) webData = [[NSMutableData data] retain];
并在connectionDidFinishLoading ..
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *gotXml = [[NSString alloc]
initWithBytes: [webData mutableBytes]
length:[webData length]
encoding:NSUTF8StringEncoding];
由于
答案 0 :(得分:1)
是的,只要网址中包含https://,就会安全地发送请求。