gpt4 book ai didi

ios - SOAP 网络服务 header 错误

转载 作者:行者123 更新时间:2023-11-29 02:07:05 25 4
gpt4 key购买 nike

我是第一次使用 SOAP 服务,

这是数据服务器所期望的,

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:服务器无法识别 HTTP header SOAPAction 的值:http://www.geoming.com/setLocation。System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()”。

无法找到解决方案,因为我是 ios 新手。

最佳答案

错误的 SOAPAction。而不是 @"http://www.geoming.com/setLocation "你需要使用 @"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;}

它应该有效!

关于ios - SOAP 网络服务 header 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29676492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com