我正在发送肥皂请求。但是没有数据被返回。Web 服务不返回任何错误。我无法弄清楚出了什么问题。它与UTF8编码有关吗?请帮忙。下面是我的代码:
NSString *xmlString = @"<ServiceCalls xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><ServiceCall><Phone_No>033542390843</Phone_No></ServiceCall></ServiceCalls>";
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"
"<GetVehiclesByPhone_ServiceCall_Proc xmlns=\"http://tempuri.org/\">\n"
"<xmlStr>%@</xmlStr>\n"
"<m_LoginId>Username</m_LoginId>\n"
"<m_pass>Password</m_pass>\n"
"</GetVehiclesByPhone_ServiceCall_Proc>\n"
"</soap:Body>\n"
"</soap:Envelope>", xmlString];
NSLog(@"%@", soapMessage);
NSURL *url = [NSURL URLWithString:@"http://103.9.23.21/TPL_Web_Services/TPLInterface.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://tempuri.org/GetVehiclesByPhone_ServiceCall_Proc" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response;
NSError *error;
NSData *webData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
if (webData != nil) {
NSString *data = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
NSLog(@"Data: %@", data);
if (error == nil) {
if ([data isEqualToString:@"True"] || [data isEqualToString:@"true"]) {
[self showSuccessfulAlert];
[self storeDefaults];
[self.dataLayer notifySplashRemoved];
}
else {
/*UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Data!" message:@"The phone no. you entered is not registered." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];*/
sendSMS = YES;
}
}
else {
sendSMS = YES;
}
}
else {
sendSMS = YES;
}