0

我编写了一个函数来从 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];
}
4

1 回答 1

3

我看到您正在访问 SOAP Web 服务。而且您已经在 SOAP 消息中将数据发送到您的 Web 服务。

由于这是一个 SOAP API,您只需更改[theRequest addValue: @"http://methodoor.com/checkupservice/GetUserList" forHTTPHeaderField:@"SOAPAction"];可以从 WSDL 或 SVC 文件获取的 SOAP 操作和 SOAP 消息,以访问您的 Web 服务的另一种方法。

有关更多信息,您可以查看链接。希望这可以帮助。

于 2013-05-16T12:36:19.900 回答