我编写了一个函数来从 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];
}
最佳答案
我看到您正在访问 SOAP 网络服务。您已经在 SOAP 消息中将数据发送到 Web 服务。
由于这是一个 SOAP API,您只需更改 SOAP Action [theRequest addValue: @"http://methodor.com/checkupservice/GetUserList"for HTTPHeaderField:@"SOAPAction"];
和 SOAP 消息,您可以从 WSDL 或 SVC 文件中获取这些消息,以访问 Web 服务的另一种方法。
有关更多信息,您可以查看 this关联。希望这会有所帮助。
关于ios - 向网络服务发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16587368/