目前我正在iOS中使用块来消费一个SOAP Web服务,我的源代码如下:
NSString *xml = requestXMLToSent;
NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[xml length]];
NSURL *serviceURL = [NSURL URLWithString: url];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:serviceURL];
[urlRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue: serviceURL forHTTPHeaderField:@"SOAPAction"];
[urlRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[urlRequest setHTTPBody: [xml dataUsingEncoding:NSUTF8StringEncoding]];
[urlRequest setHTTPMethod:@"POST"];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError == NULL) {
NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *) response;
NSInteger statuscode = httpResponse.statusCode;
if (statuscode == 200) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"response String : %@",responseString);
}else{
NSLog(@"%@",response);
}
}else{
NSLog(@"There is an error in URL connection and the Error is : %@",connectionError);
}
我在控制台上遇到了以下错误:
NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
URL连接存在错误,错误提示为: 错误域=NSURLErrorDomain,错误代码=-1202,“此服务器的证书无效。您可能正在连接到一个假冒成“www.xxxxxxxx.net”的服务器,这可能会危及您的机密信息。” UserInfo=0x10948bbb0 {NSUnderlyingError=0x109470d10 “此服务器的证书无效。您可能正在连接到一个假冒成“www.xxxxxx.net”的服务器,这可能会危及您的机密信息。”,NSErrorFailingURLStringKey=https://www.----------------------------------, NSErrorFailingURLKey=https://-------------------------,NSLocalizedRecoverySuggestion=是否仍要连接到服务器?,NSURLErrorFailingURLPeerTrustErrorKey=,NSLocalizedDescription=此服务器的证书无效。您可能正在连接到一个假冒成“www.xxxxxx.net”的服务器,这可能会危及您的机密信息。}