如何使用AFNetworking库调用.NET XML Web服务

aza*_*arp 3 ios afnetworking

我使用以下代码来调用http://www.highoncoding.com/Customers.asmx Web服务.

更新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];
Run Code Online (Sandbox Code Playgroud)

但它不是返回XML而是返回HTML/CSS.

更新2:

我错过了httpMethod行:

[request setHTTPMethod:@"POST"];
Run Code Online (Sandbox Code Playgroud)

Ben*_*man 7

您需要设置Content-TypeSOAPAction作为标题.您的SOAP XML字符串需要是请求的邮件正文.

我建议使用SOAPClient,HTTPClient或只是原始curl构建此请求,然后使用AFNetworking进行随机攻击.

将此原始请求与AFNetworking生成的请求进行比较,以查看使用像Charles这样的代理所存在的差异.

更新:这是一个有效的原始请求示例

HTTP客户端手动发出SOAP请求

并回应:

响应