ios - 向网络服务发送参数

标签 ios objective-c web-services

我编写了一个函数来从 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/

相关文章:

java - 旧版应用程序可在同一服务器或通过 ws 访问

ios - 使用 NSMutableURLRequest/URLRequest 请求 http

iphone - 将新电话号码添加到联系人应用程序

ios - Google geocoding api OVER_QUERY_LIMIT 在 5 个请求后发生

ios - 如何从Objective c中的MKMapKit中删除 map 位置和注释

c# - 从 VS 2012 升级到 VS 2013 后 WebServices 不工作

ios - 你如何快速设置 Mapbox map 的间距?

ios - 检查字符串是否包含大于

ios - 做一个音乐播放器应用程序!上一轨道和下一轨道

VB Request.InputStream 的 Java 等效项