我使用以下代码来调用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];
但它不是返回XML而是返回HTML / CSS。
更新2:
我错过了httpMethod专栏:
[request setHTTPMethod:@"POST"];
答案 0 :(得分:7)
您需要将Content-Type
和SOAPAction
设置为标题。您的SOAP XML字符串必须是请求的邮件正文。
我建议在使用AFNetworking进行随机攻击之前使用SOAPClient,HTTPClient或只是原始卷曲构建此请求。
将此原始请求与AFNetworking生成的请求进行比较,以使用Charles之类的代理查看差异所在。
更新:以下是有效的原始请求的示例
回复: