我想访问一个网络服务,想传递 2 个参数。
当我运行下面的代码时,会显示此错误:
@countryname not supplied
我已经将 2 个参数传递为txtcity
和txtcountry
。
-(IBAction)FindWords:(id)sender
{
NSString *soapMsg =
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<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/\">"
"<soap:Body>"
"<GetWeather xmlns=\"http://www.webserviceX.NET/\">"
"<CityName>%@</CityName>"
"<CountryName>%@</CountryName>"
"</GetWeather>"
"</soap:Body>"
"</soap:Envelope>", txtCity.text,txtCounrty.text];
//---print it to the Debugger Console for verification---
NSLog(@"%@",soapMsg);
NSURL *url = [NSURL URLWithString:
@"http://www.webservicex.net/globalweather.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
//---set the various headers---
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
NSLog(@"WebData....%@",soapMsg);
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://www.webserviceX.NET/GetWeather" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
//---set the HTTP method and body---
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
//---start animating--
[activityIndicator startAnimating];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if(conn)
{
webData = [[NSMutableData data] retain];
NSLog(@"WebDatanew....%@",webData);
}
}