Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios中对服务器的SOAP请求_Ios_Xml_Web Services_Soap - Fatal编程技术网

ios中对服务器的SOAP请求

ios中对服务器的SOAP请求,ios,xml,web-services,soap,Ios,Xml,Web Services,Soap,我在以SOAP格式请求服务器时遇到问题。当我在浏览器中粘贴Soap信封时(仅用于测试web服务),它会给出正确的响应。但当我从应用程序请求时,它会给我不相关的响应。 我搜索了很多,但在每个地方我都找到了相同的soap请求技术。 这是我正在使用的代码 NSString *soapMessage = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<soap:Envel

我在以SOAP格式请求服务器时遇到问题。当我在浏览器中粘贴Soap信封时(仅用于测试web服务),它会给出正确的响应。但当我从应用程序请求时,它会给我不相关的响应。 我搜索了很多,但在每个地方我都找到了相同的soap请求技术。 这是我正在使用的代码

    NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">\n"
"<soap:Body>\n"
"<ProfileLogin xmlns=\"http://tempuri.org/\">"
"<strLoginRequest>"
"<email>abc@gmail.com.au</email>"
"<password>123456</password>"
"</strLoginRequest>"
" </ProfileLogin>"
"</soap:Body>"
"</soap:Envelope>"
];
NSLog(soapMessage);

NSURL *url = [NSURL URLWithString:@"http://www.abc.com.au/mobileapp.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest setValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setValue:@"http://tempuri.org/ProfileLogin" forHTTPHeaderField:@"SOAPAction"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if( theConnection )
{
    webData = [[NSMutableData data] retain];
}
else
{
    NSLog(@"theConnection is NULL");
}
NSString*soapMessage=[NSString stringWithFormat:
@“\n”
“\n”
“\n”
""
""
"abc@gmail.com.au"
"123456"
""
" "
""
""
];
NSLog(soapMessage);
NSURL*url=[NSURL URLWithString:@”http://www.abc.com.au/mobileapp.asmx"];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]];
[TheRequestSetValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”];
[请求设置值:msgLength for HttpHeaderField:@“内容长度”];
[请求设置值:@”http://tempuri.org/ProfileLoginforHTTPHeaderField:@“SOAPAction”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding];
NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
if(连接)
{
webData=[[NSMutableData]保留];
}
其他的
{
NSLog(@“连接为空”);
}
并得到回应

根级别的FalseData无效。第1行,位置1

请让一些好友告诉我这是我的错,或者是服务器端的错。

试试看

[theRequest setValue:@"application/soap+xml;charset = utf-8" forHTTPHeaderField:@"Content-Type"];
试试这个

[theRequest setValue:@"ProfileLogin" forHTTPHeaderField:@"SOAPAction"];
而不是

[theRequest setValue:@"http://tempuri.org/ProfileLogin" forHTTPHeaderField:@"SOAPAction"];

@我试过一个包,但它给了我答案。服务器无法为请求提供服务,因为媒体类型不受支持。@aloksrivastava可能您认为msgLength是错误的。是[soapMessage dataUsingEncoding:NSUTF8StringEncoding]中NSData返回的长度;服务器无法识别HTTP标头SOAPAction:ProfileLogin的值。