我是 iphone 开发的新手。
我正在尝试从 iphone 应用程序将 NSSTRING 发送到服务器。
使用以下代码行
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap12:Body>\n"
"<SaveData xmlns=\"http://tempuri.org/\">\n"
"<xmlstring>%@</xmlstring>\n"
"</SaveData>\n"
"</soap12:Body>\n"
"</soap12:Envelope>\n", StringXml
];
NSLog(@"Soap Messaage......%@",soapMessage);
NSURL *url = [NSURL URLWithString:urlString];
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/SaveData" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
// [theRequest addValue: StringXml forHTTPHeaderField:@"xmlstring"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
//[theRequest setHTTPBody: [StringXml dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connectionResponse = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
但它返回给我错误的回复
IE
System.InvalidOperationException:请求格式无效:text/xml;字符集=utf-8。在 System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() 在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
如何克服这个问题?