【发布时间】:2010-10-12 12:49:06
【问题描述】:
我在使用 ASIHTTPRequest 获得响应时遇到了一些麻烦,这很伤脑筋。 我在 ASIHTTPRequest 的 POST-Body 中向服务器发送一个 SOAP 请求。 到目前为止,请求发送良好,但根据控制台,响应字符串为“(null)”,响应数据的长度为 0。 但是,当我发送 SOAP-Body 字符串时,我使用 NSLog(); 将其放入控制台;使用 Firefox 插件“POSTER”到服务器,我得到了我想要的响应。另一方面,只要 SOAP-Request 中有错误,就会在 ASIHTTPRequest 中得到响应。 到目前为止,我完全没有想法,如果有人能提供帮助,那就太好了。
这是我的代码。
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:myURL];
[request addRequestHeader:@"Content-Type" value:@"text/xml"];
NSLog(@"XML: %@",[carInsurance buildXMLString]); //Debug output
NSMutableData *theData = [[carInsurance buildXMLString] dataUsingEncoding:NSUTF8StringEncoding];
[request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d",[theData length]]];
[request setPostBody:theData];
[request setRequestMethod:@"POST"];
NSLog(@"Headers before: %@",[[request requestHeaders] description]); //Debug output
[request startSynchronous];
NSLog(@"Headers after: %@",[[request requestHeaders] description]);
比较好奇的是我的 Debug 标头。
2010-10-12 14:39:11.945 appname[12484:207] 之前的标头:{ “内容长度”= 1944; “内容类型”=“文本/xml”; }
【问题讨论】:
标签: iphone objective-c asihttprequest