问题描述
我在IOS中使用ASIHTTPRequest。我有一个wsdl / soap Web服务。
当我打电话给我的网站服务时,我收到了错误400错误的请求。我正在使用此代码:
NSData *xmlData = // I construct the soap message witk soapui
NSURL *url = [NSURL URLWithString:@\"https:myUrlWSDL\"];
self.currentRequest = [ASIFormDataRequest requestWithURL:url];
[self.currentRequest appendPostData:xmlData];
[self.currentRequest setDelegate:self];
[self.currentRequest startAsynchronous];
[[currentRequest requestHeaders] description];
NSLog(@\"Headers %@\",[currentRequest requestHeaders]);
NSLog向我展示:标头(空)。
我的第一个问题,为什么Headers为null?这正常吗?
在控制台中,我有400个错误的请求。
在代表中,我这样做:
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@\"headers: %@\",[self.currentRequest responseHeaders]);
}
它告诉我:
\"Cache-Control\" = \"no-store,no-cache,must-revalidate,post-check=0,pre-check=0\";
Connection = close;
\"Content-Encoding\" = gzip;
\"Content-Length\" = 285;
\"Content-Type\" = \"text/xml; charset=utf-8\";
Date = \"Fri,10 Jun 2011 01:25:40 GMT\";
Expires = \"Thu,19 Nov 1981 08:52:00 GMT\";
Pragma = \"no-cache\";
Server = Apache;
\"Set-Cookie\" = \"symfony=...4; path=/\";
Vary = \"Accept-Encoding,User-Agent\";
\"X-Powered-By\" = \"PHP/5.3.3\";
我的问题是:为什么400错误请求错误?我的要求是什么问题?还是问题出在我的肥皂上?
感谢您的回答。
解决方法
据我所知,在发出SOAP / WSDL请求时,您需要在请求中设置一些标头
Content-Type: text/xml
Content-Length: length of your message in bytes
SOAPAction: your SOAPAction goes here
ASIHTTPRequest设置内容长度本身(不确定内容类型)。但是,您将不得不自己添加SOAPAction标头。