Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

GokulKrish

macrumors newbie
Original poster
Apr 12, 2014
11
0
Chennai
I am using this snippet to get data from an url .


Code:
-(int) GetData : (NSString *) urlstr : (NSData **) bufferdata
{
     int retcode =0;
     NSError *errorobj = nil;
     NSHTTPURLResponse *httpresponse;
     NSData *buffer;
 
     @try
      {
              retcode = 0;
 
              NSLog(@"url string:%@\n",urlstr);
 
              NSURL *urlobj = [NSURL URLWithString: urlstr];
              NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlobj cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
 
              [request setValue:@"close" forHTTPHeaderField:@"Connection"];
 
              [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[urlobj host]];
 
              buffer = [NSURLConnection sendSynchronousRequest:request returningResponse:&httpresponse error:&errorobj];
 
              self->httpStatusCode =[B] [httpresponse statusCode];[/B]
 
              [B]NSLog(@"Http response status code: %i: Description:%@\n",self->httpStatusCode,[NSHTTPURLResponse localizedStringForStatusCode:self->httpStatusCode]);[/B]
 
              if(self->httpStatusCode == 200)
              {
                  *bufferdata = buffer;
                  isconnectionSuccess = TRUE;
              }
              else {
                  *bufferdata = nil;
                  isconnectionSuccess = FALSE;
                  retcode = 1;
              }
 
              //errorobj will be set to some only if intended response is received
              if (errorobj)
              {
                  retcode =  [errorobj code];
                  NSLog(@"Error Description: %@\n", [errorobj localizedDescription]);
                  isconnectionSuccess = FALSE;
              }
      }
     @catch (NSException *exp) {
     NSLog(@"GetData: Exception occurred: %@ :reason: %@\n", [exp name],[exp reason]);
      retcode = ERROR_FAILURE;
      }
 
     return retcode;
 
}


Approximately 3 Out of 10 machines fails, but in rest 7 machines download goes fine .

I am getting following error .


Code:
Http response status code: 0: Description:server error
Error Description: Could not connect to the server.


Any ideas ? Thanks in advance ...
 
Last edited by a moderator:

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
We don't know what the other 7 machines are returning because you left that in a truncated subject line. Edit your post and describe the results there.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,744
8,418
A sea of green
The error description is "Could not connect to the server.", so that would be my first guess about what's wrong.

Your code is using HTTP, so maybe you can use a simple web browser to test the URL from the failing machine.

If the URL is actually HTTPS, maybe the problem is in the certificates. That's just a guess, since you didn't show any URLs.

If the failing servers are ones you control, you should be able to look in their logs to see if the failing clients are actually establishing a connection or not.

You might also be able to test the URLs using the 'curl' command. See its man page here:
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/curl.1.html
The simplest example of using curl is:
Code:
curl "http://www.example.com/"
You can copy and paste this into a Terminal window, and see what it does. There's a real "example.com" domain and server, maintained by ICANN:
http://en.wikipedia.org/wiki/Example.com


You didn't post the failing URL, nor say whether it's a dotted-quad or DNS name, nor say which network it's on (local subnet, enterprise network, at-large internet), so all anyone can do is make guesses about why the URL doesn't work.

You'll have to provide more details about the specific URL, whether it's reachable from the failing machines by other means (e.g. curl or a browser), and so on.

You may also need to look for common factors about the failing machines, such as they're all running a particular OS version, they're all on a particular subnet, or they all have a particular software install or setting (e.g. blocking software).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.