我正在使用以下代码来调用 http://www.highoncoding.com/Customers.asmx网络服务。
更新 1:
现在,我有以下代码:
-(NSMutableArray *) getAll
{
NSURL *baseURL = [NSURL URLWithString:@"http://highoncoding.com/Customers.asmx?op=GetAll"];
NSString *soapBody = @"<?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> <GetAll xmlns=\"http://tempuri.org/\" /></soap:Body></soap:Envelope>";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:baseURL];
[request setHTTPBody:[soapBody dataUsingEncoding:NSUTF8StringEncoding]];
[request addValue:@"http://tempuri.org/GetAll" forHTTPHeaderField:@"SOAPAction"];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start];
但不是返回 XML,而是返回 HTML/CSS。
更新 2:
我错过了 httpMethod 行:
[request setHTTPMethod:@"POST"];
最佳答案
您需要将 Content-Type
和 SOAPAction
设置为 header 。您的 SOAP XML 字符串需要是请求的发布正文。
我建议在使用 AFNetworking 进行随机测试之前,使用 SOAPClient、HTTPClient 或仅使用原始 curl 构建此请求。
将此原始请求与 AFNetworking 生成的请求进行比较,以使用类似 Charles 的代理查看差异所在.
更新:这是一个有效的原始请求示例
响应:
关于ios - 如何使用 AFNetworking 库调用 .NET XML Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11210723/