Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP error 408 accessing web service

I am sending a POST request from iPhone to a webservice, which is a REST layer over SOAP. I am getting Error 408 Request Timeout, testing on both the iPhone device and simulator. When testing with the simulator, I noticed that if I access the webserver from a browser first, then run the simulator, the problem goes away and communication works. Behaviour is very similar to this question HTTP, 408 Request timeout Here is the code I am using to create the POST request. Has anyone come across this behaviour, and found a solution?

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; 
like image 735
primulaveris Avatar asked Mar 24 '26 11:03

primulaveris


1 Answers

sorry for my english,

i faced with this stution, too. My application is an exe that calls a webservice. the webservice is coded with apache cxf. Then, i got an error "The remote server returned an unexpected response (408) Request timeout" in client side. but if i access the wsdl from a browser first, my exe runned successfully. i haven't found any solution. i add the fallowing codes before calls the webservice.

WebClient x = new WebClient();

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

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

It does the same thing with browser. this solved the problem. but normally, we don’t need to add this code.

Then, I changed the webservise coding. I used Axis2. but my problem is not solved. I thought this problem related to firewall.

Connection to webservice times out first time

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

like image 181
user974510 Avatar answered Mar 26 '26 02:03

user974510



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!