如何使用SOAP的Web服务发送HTTPS同步请求到服务器
问题描述:
代码:如何使用SOAP的Web服务发送HTTPS同步请求到服务器
NSString *[email protected]"http://projdemo.com/MobileWebServices/Service.asmx";
soapRequestStr = [self CreateRequest];
NSString* soapAction;
soapAction [email protected]"http://www.projdemo.com/FetchAll";
urlRequest=NULL;
responseData=NULL;
httpBodyData=[soapRequestStr dataUsingEncoding: NSUTF8StringEncoding];
url=[[NSURL alloc]initWithString: urlString];
urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:httpBodyData];
[urlRequest setValue:@"projdemo.com" forHTTPHeaderField:@"Host"];
[urlRequest setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[urlRequest setValue:[NSString stringWithFormat:@"%d",[soapRequestStr length]]
forHTTPHeaderField:@"Content-Length"];
[urlRequest setValue:soapAction forHTTPHeaderField:@"SOAPAction"];
responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil
error:nil];
response = nil;
error = nil;
responseString=NULL;
responseString = [[NSString alloc] initWithData:responseData
encoding:NSASCIIStringEncoding];
NSLog(@"data is %@",responseData);
NSLog(@"Response string is %@",responseString);
soapRequestStr是我们要传递给服务器的XML文件格式的字符串。在这里它的做工精细,当URL变成https其获得响应,
错误响应:
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.20 (Ubuntu) Server at projdemo.com Port 443</address>
</body></html>
答
Parsing xml:
NSXMLParser *parser;
parser = [[NSXMLParser alloc]initWithContentsOfURL:
[NSURLURLWithString:@"urPath/webservice"]];
[parser setDelegate:self];
[parser parse];
// THEN USE THESE DELEGATES
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog("%@",elementName);//starting tag
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSLog("%@",string);//THE VALUE
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog("%@",elementName);//END TAG
}
+0
感谢您的回应,在这里我没有得到响应数据给paese。 – user1280935 2012-03-21 04:45:49
+0
我的问题是如何在URL保护时发送soap请求liks https – user1280935 2012-03-21 04:46:34
请不要只是发布您的代码和错误消息。堆栈溢出不是代码调试服务。请查看[faq]了解更多关于Stack Overflow如何工作的信息。 – cdeszaq 2012-03-20 13:50:27
@ user1280935看看这个 - > http://sudzc.com/ – 2012-03-20 15:00:29