一:Using SO AP 1.1
Host: www.ecubicle.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: “http://www.ecubicle.net/webservices/FindCountryAsXml”
xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/“>
(1)请求的webservice url的地址为“http://www.ecubicle.net/iptocountry.asmx”
(2)url 的 SOAPAction 是 “http://www.ecubicle.net/webservices/FindCountryAsXml”
(3) 请求的Content-Type 格式为“text/xml; charset=utf-8.”
(4)请求的方式为post
(5)请求的内容(SOAP request)格式为
xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/“>
(6)请的内容长度(Content-Length)为SOAP request的字节长度
(7)返回的结果格式为
Content-Type: text/xml; charset=utf-8
Content-Length: length
xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/“>
- (IBAction)buttonClicked:(id)sender {
NSString *soapMsg =[NSString stringWithFormat:@“”
“
“
“
//---print it to the Debugger Console for verification---
NSLog(soapMsg);
NSURL *url = [NSURL URLWithString:@“http://www.ecubicle.net/iptocountry.asmx”];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
//---set the various headers---
NSString *msgLength = [NSString stringWithFormat:@“%d”, [soapMsg length]];
[req addValue:@“text/xml; charset=utf-8” forHTTPHeaderField:@“Content-Type”];
[req addValue:@“http://www.ecubicle.net/webservices/FindCountryAsXml”forHTTPHeaderField:@“SOAPAction”];
[req addValue:msgLength forHTTPHeaderField:@“Content-Length”];
//---set the HTTP method and body---
[req setHTTPMethod:@“POST”];
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
[activityIndicator startAnimating];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}
}
二:Using SO AP 1.2
请求格式
Host: www.ecubicle.net
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
xmlns:soap12=”http://www.w3.org/2003/05/soap-envelope”>
返回结果格式
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
xmlns:soap12=”http://www.w3.org/2003/05/soap-envelope”>
请求代码同SOAP 1.1
三:Using HTTP GET
请求格式
Host: www.ecubicle.net
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
(1)请求的地址为http://www.ecubicle.net/iptocountry.asmx/FindCountryAsXml?V4IPAddress=“aa”.
发送的数据格式必须为键值对如key1=value1&key2=value2&key3=value3.
(2) 请求的Content-Type 格式为“text/xml; charset=utf-8.”
(3)请求的内容长度(Content-Length)为 0
(4)请求的方式为GET.
(5)返回结果发送为
xml result
请求发送
NSString *queryString =[NSString stringWithFormat:@“http://www.ecubicle.net/iptocountry.asmx/FindCountryAsXml?V4IPAddress=%@“,ipAddress.text];
NSURL *url = [NSURL URLWithString:queryString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req addValue:@“text/xml; charset=utf-8” forHTTPHeaderField:@“Content-Type”];
[req addValue:0 forHTTPHeaderField:@“Content-Length”];
[req setHTTPMethod:@“GET”];
[activityIndicator startAnimating];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}
}
四: Using HTTP POS T
Host: www.ecubicle.net
Content-Type: application/x-www-form-urlencoded
Content-Length: length
V4IPAddress=string
(1)请求地址为http://www.ecubicle.net/iptocountry.asmx/FindCountryAsXml
(2)Content-Type为“application/x-www-form-urlencoded”
(3)Content-Length 为V4IPAddress=string的长度。
The data to be sent is formatted as key/value pairs — key1=value1&key2=value2&key3=value3. Unlike
HTTP GET, the data are not sent through the query string; it is sent after the HTTP headers.
(4)The HTTP Method is POST.
(5)返回结果格式为
Content-Type: text/xml; charset=utf-8
Content-Length: length
xml result
请求发送
- (IBAction)buttonClicked:(id)sender {
NSString *postString =[NSString stringWithFormat:@“V4IPAddress=%@“, ipAddress.text];
NSLog(postString);
NSURL *url = [NSURL URLWithString:@“http://www.ecubicle.net/iptocountry.asmx/FindCountryAsXml”];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@“%d”, [postString length]];
[req addValue:@“application/x-www-form-urlencoded”forHTTPHeaderField:@“Content-Type”];
[req addValue:msgLength forHTTPHeaderField:@“Content-Length”];
[req setHTTPMethod:@“POST”];
[req setHTTPBody: [postString dataUsingEncoding:NSUTF8StringEncoding]];
[activityIndicator startAnimating];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}
}