Iphone Xcode发送HTTPS Soap请求

Iphone Xcode发送HTTPS Soap请求,iphone,xcode,soap,https,request,Iphone,Xcode,Soap,Https,Request,昨天,HTTPs证书安装在我的服务器上,我的Web服务正在运行。在安装HTTPs证书之前,我自制的iPhone应用程序向Web服务发送了一个SOAP请求。Web服务通过返回一条XML消息成功地进行了响应 这是我用于将soap请求发送到Web服务的代码: NSString*soapMsg=[NSString stringWithFormat:@] "" "" "" "%@" "%@" "" "" “”,参数1,参数2] NSURL *url = [NSURL URLWithString:

昨天,HTTPs证书安装在我的服务器上,我的Web服务正在运行。在安装HTTPs证书之前,我自制的iPhone应用程序向Web服务发送了一个SOAP请求。Web服务通过返回一条XML消息成功地进行了响应

这是我用于将soap请求发送到Web服务的代码:


NSString*soapMsg=[NSString stringWithFormat:@]
""
""
""
"%@"
"%@"
""
""
“”,参数1,参数2]

NSURL *url = [NSURL URLWithString:
              @"http://domain.com/webservice-name.svc"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = [NSString stringWithFormat:@"%d",
                       [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/webservice-name/method-name" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

NSURLResponse *response = nil;
NSError *error = nil;
NSData *resultsData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];

if(error){
    NSLog(@"Error sending soap request: %@", error);
    return FALSE;
}

NSLog(@"%@", soapMsg);
NSLog(@"%@", [[NSString alloc] initWithData:resultsData encoding:NSUTF8StringEncoding]);

现在,如果我将URL更改为“httpS://domain.com/webservice name.svc”,则webservice根本不会重复


要将成功的SOAP请求发送到HTTPS安全的Web服务,我必须做哪些更改?

对于正常的xml服务,使用GET方法HTTPS request对我有效。尝试我使用的这个委托方法`



您正在访问的脚本是否确实存在?e、 g.您是否尝试使用桌面浏览器访问它?(某些web服务器配置为在通过SSL加密的HTTP访问时使用完全不同的(根)文件夹)。
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSArray *trustedHosts=[NSArray arrayWithObject:@"yourdomian.com"];
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
    if ([trustedHosts containsObject:challenge.protectionSpace.host])
        [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}