gpt4 book ai didi

iphone - HTTP 错误 408 访问 Web 服务

转载 作者:可可西里 更新时间:2023-11-01 16:31:15 26 4
gpt4 key购买 nike

我正在从 iPhone 向 Web 服务发送 POST 请求,这是一个基于 SOAP 的 REST 层。我收到错误 408 请求超时,在 iPhone 设备和模拟器上进行测试。在使用模拟器进行测试时,我注意到如果我先从浏览器访问网络服务器,然后运行模拟器,问题就会消失并且通信正常。行为与这个问题非常相似 HTTP, 408 Request timeout这是我用来创建 POST 请求的代码。有没有人遇到过这种行为,并找到了解决方案?

NSString * urlString = [NSString stringWithFormat:@"%@%@", kBaseURL,method];
NSURL * myURL = [NSURL URLWithString:urlString];
NSLog(@"URL %@", myURL);

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:myURL];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest setTimeoutInterval:60]; // leave at default 60 secs
NSLog(@"Post Body: %@",body);
NSURLConnection *theConnection = [[NSURLConnection alloc]
initWithRequest:theRequest
delegate:self];
if( theConnection ) {
if (webData){
[webData release];
}
webData = [[NSMutableData data] retain];
NSLog(@"connection set up");
}
else {
NSLog(@"theConnection is NULL");
}
self.mainConnection=theConnection;
[theConnection release];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

最佳答案

对不起我的英语,

我也遇到过这种情况。我的应用程序是一个调用 web 服务的 exe。 Web 服务是用 apache cxf 编码的。然后,我在客户端收到错误“远程服务器返回意外响应(408)请求超时”。但是如果我先从浏览器访问 wsdl,我的 exe 就会成功运行。我还没有找到任何解决方案。我在调用网络服务之前添加了休闲代码。

WebClient x = new WebClient();

string source = x.DownloadString("http://......../InfoOperations?wsdl");

if (source != "")
{
// Call your web method here...
}

它对浏览器做同样的事情。这解决了问题。但通常情况下,我们不需要添加此代码。

然后,我更改了 webservise 编码。我使用了 Axis2。但我的问题没有解决。我认为这个问题与防火墙有关。

Connection to webservice times out first time

http://www.mustafakurkcu.com/java/230-cxfclientreturn408.html

关于iphone - HTTP 错误 408 访问 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5297157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com