Web サービスにアクセスしたい、2 つのパラメーターを渡したい。
以下のコードを実行すると、次のエラーが表示されます。
@countryname not supplied
私はすでに2つのパラメータをtxtcity
andとして渡しています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);
}
}