iphone - HTTP 错误 408 访问 Web 服务

标签 iphone web-services http http-status-code-408

我正在从 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/

相关文章:

http - 我怎么知道一个表单被提交了两次?

javascript - 服务器无法使用从 Electron 应用程序发送的应用程序/xml 请求

ios - 如何在 iPhone 设备上使用 AVAudioSessionCategoryMultiRoute?

web-services - WSIT、Maven 和 wsimport——它们可以一起工作吗?

Android httpUrlConnection发送和接收数据

python - 用于创建RESTful Web服务的Node vs python

iPhone:单独的描边和填充不起作用

jquery - 获取真实的 iPhone 分辨率 - jquery

iphone - C 中的应用程序开发。

angularjs - 从 Angular 向 nodejs 发送 https 请求。无法发送任何数据