将参数发送到Web服务 [英] Send parameters to a web service
问题描述
开始之前:我正在使用目标C为Iphone编程.
Before I start: I'm programming for Iphone, using objective C.
我已经使用NSURLRequest和NSURLConnection实现了对Web服务功能的调用.然后,该函数将返回包含所需信息的XML.
I have already implemented a call to a web service function using NSURLRequest and NSURLConnection. The function then returns a XML with the info I need.
代码如下:
NSURL *url = [NSURL URLWithString:@"http://myWebService/function"];
NSMutableURLRequest theRequest = [[NSMutableURLRequest alloc] initWithURL:url];
NSURLConnection theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
我还实现了方法
- didRecieveResponse
- didRecieveAuthenticationChallenge
- didRecievedData
- didFailWithError
- connectionDidFinishLoading.
而且效果很好.
现在,我需要向该函数发送2个参数:位置"和模块".
我尝试使用以下修改:
Now I need to send 2 parameters to the function: "location" and "module".
I tried using the following modification:
NSMutableURLRequest theRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[theRequest setValue:@"USA" forHTTPHeaderField:@"location"];
[theRequest setValue:@"DEVELOPMENT" forHTTPHeaderField:@"module"];
NSURLConnection theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
但是它似乎不起作用. 我做错了吗?有没有办法知道我是否为参数使用了错误的名称(例如,可能是"Location"或"LOCATION",还是没关系?)? 或一种方法来知道函数正在等待哪些参数...
But it doesn't seem to work. I'm doing something wrong? is there a way to know if I'm using the wrong names for the parameters (as maybe it is "Location" or "LOCATION" or it doesn't matter?)? or a way to know which parameters is the function waiting for...
其他信息:
我无权访问Web服务的源,因此无法对其进行修改.
但是我可以访问WSDL.使函数说出来的人就在那里...但是我对此毫无意义>.< ...
Extra info:
I don't have access to the source of the web service so I can't modify it.
But I can access the WSDL. The person who made the function say is all there... but I can't make any sense of it >.<...
任何帮助将不胜感激. :)
推荐答案
关于GET Post SOAP的一些示例
some examples about GET Post SOAP
获取请求
GET /index.html?userid=joe&password=guessme HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
发布请求
POST /login.jsp HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
Content-Length: 27
Content-Type: application/x-www-form-urlencoded
userid=joe&password=guessme
肥皂请求
POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
HOST,User-Agent,Content-Length,Content-Type是请求标头中的项目
the HOST,User-Agent,Content-Length,Content-Type are items in the Request Header
这篇关于将参数发送到Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!