SOAP 网络服务 header 错误
SOAP webservice header error
我是第一次使用肥皂服务,
这是数据服务器,
POST /updateLocation.asmx HTTP/1.1
Host: www.geoming.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<setLocation xmlns="http://geoming.com/">
<pLati>string</pLati>
<pLongi>string</pLongi>
<pStatusMsg>string</pStatusMsg>
<pID>string</pID>
<pSpeed>string</pSpeed>
<pStreet1>string</pStreet1>
<pStreet2>string</pStreet2>
<pCity>string</pCity>
<pState>string</pState>
<pCountry>string</pCountry>
<pDate>string</pDate>
<pTimeZone>string</pTimeZone>
</setLocation>
</soap12:Body>
</soap12:Envelope>
在 objective c 部分我是这样做的,
soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope/\">"
"<soap12:Body>"
"<setLocation xmlns=\"http://www.geoming.com/\">"
"<pLati>-33.868</pLati>"
"<pLongi>151.2086</pLongi>"
"<pStatusMsg>santanu test</pStatusMsg>"
"<pID>3</pID>"
"<pSpeed>12</pSpeed>"
"<pStreet1>CD - 96</pStreet1>"
"<pStreet2>Salt lake city</pStreet2>"
"<pCity>kolkata</pCity>"
"<pState>west bengal</pState>"
"<pCountry>india</pCountry>"
"<pDate>16-04-2015</pDate>"
"<pTimeZone>-5.30</pTimeZone>"
"</setLocation>"
"</soap12:Body>"
"</soap12:Envelope>"];
//Now create a request to the URL
NSURL *url = [NSURL URLWithString:@"http://www.geoming.com/updateLocation.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
//ad required headers to the request
[theRequest addValue:@"www.geoming.com" forHTTPHeaderField:@"Host"];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://www.geoming.com/setLocation" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
一直显示"System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://www.geoming.com/setLocation. System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()"。
无法找到解决方案,因为我是 ios 的新手。
将您的字符串更改为
soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\
<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope/\">\
<soap12:Body>\
<setLocation xmlns=\"http://www.geoming.com/\">\
<pLati>-33.868</pLati>\
<pLongi>151.2086</pLongi>\
<pStatusMsg>santanu test</pStatusMsg>\
<pID>3</pID>\
<pSpeed>12</pSpeed>\
<pStreet1>CD - 96</pStreet1>\
<pStreet2>Salt lake city</pStreet2>
<pCity>kolkata</pCity>\
<pState>west bengal</pState>\
<pCountry>india</pCountry>\
<pDate>16-04-2015</pDate>\
<pTimeZone>-5.30</pTimeZone>\
</setLocation>
</soap12:Body>\
</soap12:Envelope>"];
错误的 SOAPAction。取而代之的是@"http://www.geoming.com/setLocation" you need use @"http://geoming.com/setLocation"
试试我的代码:
static NSString* const cstrSetLocMsg = @"<?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>"
"<setLocation xmlns=\"http://geoming.com/\">"
"<pLati>-33.868</pLati>"
"<pLongi>151.2086</pLongi>"
"<pStatusMsg>santanu test</pStatusMsg>"
"<pID>3</pID>"
"<pSpeed>12</pSpeed>"
"<pStreet1>CD - 96</pStreet1>"
"<pStreet2>Salt lake city</pStreet2>"
"<pCity>kolkata</pCity>"
"<pState>west bengal</pState>"
"<pCountry>india</pCountry>"
"<pDate>16-04-2015</pDate>"
"<pTimeZone>-5.30</pTimeZone>"
"</setLocation>"
"</soap:Body>"
"</soap:Envelope>";
并创建请求:
+ (NSMutableURLRequest*) requestSetLoc{
NSString *_soapMsg = cstrSetLocMsg;
NSURL *url = [NSURL URLWithString:@"http://www.geoming.com/updateLocation.asmx"];
NSMutableURLRequest *req = [[[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.f] autorelease];
NSString *msgLength = [NSString stringWithFormat:@"%d", [_soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://geoming.com/setLocation" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [_soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
return req;}
它应该有效!
我是第一次使用肥皂服务,
这是数据服务器,
POST /updateLocation.asmx HTTP/1.1
Host: www.geoming.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<setLocation xmlns="http://geoming.com/">
<pLati>string</pLati>
<pLongi>string</pLongi>
<pStatusMsg>string</pStatusMsg>
<pID>string</pID>
<pSpeed>string</pSpeed>
<pStreet1>string</pStreet1>
<pStreet2>string</pStreet2>
<pCity>string</pCity>
<pState>string</pState>
<pCountry>string</pCountry>
<pDate>string</pDate>
<pTimeZone>string</pTimeZone>
</setLocation>
</soap12:Body>
</soap12:Envelope>
在 objective c 部分我是这样做的,
soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope/\">"
"<soap12:Body>"
"<setLocation xmlns=\"http://www.geoming.com/\">"
"<pLati>-33.868</pLati>"
"<pLongi>151.2086</pLongi>"
"<pStatusMsg>santanu test</pStatusMsg>"
"<pID>3</pID>"
"<pSpeed>12</pSpeed>"
"<pStreet1>CD - 96</pStreet1>"
"<pStreet2>Salt lake city</pStreet2>"
"<pCity>kolkata</pCity>"
"<pState>west bengal</pState>"
"<pCountry>india</pCountry>"
"<pDate>16-04-2015</pDate>"
"<pTimeZone>-5.30</pTimeZone>"
"</setLocation>"
"</soap12:Body>"
"</soap12:Envelope>"];
//Now create a request to the URL
NSURL *url = [NSURL URLWithString:@"http://www.geoming.com/updateLocation.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
//ad required headers to the request
[theRequest addValue:@"www.geoming.com" forHTTPHeaderField:@"Host"];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://www.geoming.com/setLocation" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
一直显示"System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://www.geoming.com/setLocation. System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()"。
无法找到解决方案,因为我是 ios 的新手。
将您的字符串更改为
soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\
<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope/\">\
<soap12:Body>\
<setLocation xmlns=\"http://www.geoming.com/\">\
<pLati>-33.868</pLati>\
<pLongi>151.2086</pLongi>\
<pStatusMsg>santanu test</pStatusMsg>\
<pID>3</pID>\
<pSpeed>12</pSpeed>\
<pStreet1>CD - 96</pStreet1>\
<pStreet2>Salt lake city</pStreet2>
<pCity>kolkata</pCity>\
<pState>west bengal</pState>\
<pCountry>india</pCountry>\
<pDate>16-04-2015</pDate>\
<pTimeZone>-5.30</pTimeZone>\
</setLocation>
</soap12:Body>\
</soap12:Envelope>"];
错误的 SOAPAction。取而代之的是@"http://www.geoming.com/setLocation" you need use @"http://geoming.com/setLocation"
试试我的代码:
static NSString* const cstrSetLocMsg = @"<?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>"
"<setLocation xmlns=\"http://geoming.com/\">"
"<pLati>-33.868</pLati>"
"<pLongi>151.2086</pLongi>"
"<pStatusMsg>santanu test</pStatusMsg>"
"<pID>3</pID>"
"<pSpeed>12</pSpeed>"
"<pStreet1>CD - 96</pStreet1>"
"<pStreet2>Salt lake city</pStreet2>"
"<pCity>kolkata</pCity>"
"<pState>west bengal</pState>"
"<pCountry>india</pCountry>"
"<pDate>16-04-2015</pDate>"
"<pTimeZone>-5.30</pTimeZone>"
"</setLocation>"
"</soap:Body>"
"</soap:Envelope>";
并创建请求:
+ (NSMutableURLRequest*) requestSetLoc{
NSString *_soapMsg = cstrSetLocMsg;
NSURL *url = [NSURL URLWithString:@"http://www.geoming.com/updateLocation.asmx"];
NSMutableURLRequest *req = [[[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.f] autorelease];
NSString *msgLength = [NSString stringWithFormat:@"%d", [_soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://geoming.com/setLocation" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [_soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
return req;}
它应该有效!