我编写了一个函数来从Web服务获取响应。但现在我想将参数发送到Web服务。如何修改以下代码以将参数发送到其他Web服务?我想使用下面的代码,我是IOS的新手,不想搞砸,因为我有一个正常工作的代码。
- (IBAction)buttonClick:(id)sender {
recordResults = FALSE;
NSString *soapMessage = [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"
"<GetUserList xmlns=\"http://methodoor.com/checkupservice/\" />\n"
"</soap:Body>\n"
"</soap:Envelope>\n"];
//NSLog(soapMessage);
_lbl_result.text = soapMessage;
NSURL *url = [NSURL URLWithString:@"http://servicing2.rotanet.com.tr/service.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://methodoor.com/checkupservice/GetUserList" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
//[nameInput resignFirstResponder];
}
答案 0 :(得分:3)
我看到您正在访问SOAP Web服务。您已经在SOAP消息中将数据发送到Web服务。
由于这是一个SOAP API,您只需要更改SOAP Action [theRequest addValue: @"http://methodoor.com/checkupservice/GetUserList" forHTTPHeaderField:@"SOAPAction"];
和SOAP消息(可以从WSDL或SVC文件中获取),以访问Web服务的另一种方法。
有关详细信息,请查看this链接。希望这会有所帮助。