在很多的情况下,我们会常常遇到webservive写的接口,往往这种情况下,我们就需要拼接一段报文去与服务器对接
首先要明白webService的工作原理,,,(http://www.cnblogs.com/Jessy/p/3528341.html)
//假如在这开始请求
NSString *webServiceBodyStr = [NSString stringWithFormat:
@"<Jsjy_yjy xmlns=\"http://xxxxx.com/webservice/\">"
"<name>wanger</name>"
"<pagenow>1</pagenow>"
"<pagesize>20</pagesize>"
"</Jsjy_yjy>"];//这里是参数
NSString *webServiceStr = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"%@\n"
"</soap:Body>\n"
"</soap:Envelope>",
webServiceBodyStr];//webService头
NSString *SOAPActionStr = [NSString stringWithFormat:@"http://xxx.com/webservice/%@", @"Jsjy_yjy"];//SOAPAction
NSURL *url = [NSURL URLWithString:@"http://xxxx/key/MurpjsjyService.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%ld", webServiceStr.length];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-type"];
[theRequest addValue:SOAPActionStr forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[webServiceStr dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConn) {
}else {
}