Unable to start HTTP connection

1,291 views
Skip to first unread message

James Abley

unread,
Aug 12, 2010, 11:07:14 AM8/12/10
to ASIHTTPRequest
Hi all,

I created a new iPhone project today, added ASIHTTPRequest (running
off HEAD - b60d4f2f2dec7c47fcb76d8975d69c1f1f714449) to it in the
usual way and yet I always get an error. Here's the code:

request_ = [[ASIHTTPRequest requestWithURL:[self url]] retain];
[request_ addRequestHeader:@"User-Agent" value:@"iPhone"];
[request_ startSynchronous];

if ([request_ error]) {
NSLog(@"%@:%@ %@", self, NSStringFromSelector(_cmd), [request_
error]);
}

The consistent error is:

Error Domain=ASIHTTPRequestErrorDomain Code=6 "Unable to start HTTP
connection" UserInfo=0x5a1eeb0 {NSLocalizedDescription=Unable to start
HTTP connection}

I've added some NSURLConnection usage into the same app to ensure that
there is network connectivity - that is working fine.

I've looked at the code and the failure is around here

http://github.com/pokeb/asi-http-request/blob/master/Classes/ASIHTTPRequest.m#L1134

CFReadStreamOpen is returning NO.

Can anyone help me understand why I might be getting this problem?

Cheers,

James

James Abley

unread,
Aug 13, 2010, 5:48:51 AM8/13/10
to ASIHTTPRequest
OK, user error as I suspected, but a strange one.

As mentioned, I was using NSURLConnection to try to triangulate the
problem and that was working fine. The actual problem was a typo in
the URL.

I was passing

[NSURL URLWithString:@"http:/www.google.com/"]

rather than

[NSURL URLWithString:@"http://www.google.com/"]

to [ASIHTTPRequest requestWithURL:(NSURL*)].

Note the problem is that I missed off a slash in the hier-part of the
URI.

This was failing at the low-level call in ASIHTTPRequest that I
described.

NSURLConnection does not fail when passed in the same invalid URL and
the content is downloaded successfully.

To my mind, it would be preferable for the NSURL class method to
return nil when passed an invalid URL. It might even be a bug in
NSURL, which is allowing a URI to contain a scheme but no authority;
I've not delved into the RFC in sufficient detail.

My question here though would be is there any way of providing a
clearer error message in ASIHTTPRequest?

Cheers,

James

On Aug 12, 4:07 pm, James Abley <james.ab...@gmail.com> wrote:
> Hi all,
>
> I created a new iPhone project today, added ASIHTTPRequest (running
> off HEAD - b60d4f2f2dec7c47fcb76d8975d69c1f1f714449) to it in the
> usual way and yet I always get an error. Here's the code:
>
>     request_ = [[ASIHTTPRequest requestWithURL:[self url]] retain];
>     [request_ addRequestHeader:@"User-Agent" value:@"iPhone"];
>     [request_ startSynchronous];
>
>     if ([request_ error]) {
>         NSLog(@"%@:%@ %@", self, NSStringFromSelector(_cmd), [request_
> error]);
>     }
>
> The consistent error is:
>
> Error Domain=ASIHTTPRequestErrorDomain Code=6 "Unable to start HTTP
> connection" UserInfo=0x5a1eeb0 {NSLocalizedDescription=Unable to start
> HTTP connection}
>
> I've added some NSURLConnection usage into the same app to ensure that
> there is network connectivity - that is working fine.
>
> I've looked at the code and the failure is around here
>
> http://github.com/pokeb/asi-http-request/blob/master/Classes/ASIHTTPR...

Ben Copsey

unread,
Aug 16, 2010, 11:24:34 AM8/16/10
to asihttp...@googlegroups.com
> To my mind, it would be preferable for the NSURL class method to
> return nil when passed an invalid URL. It might even be a bug in
> NSURL, which is allowing a URI to contain a scheme but no authority;
> I've not delved into the RFC in sufficient detail.

Not sure - certainly, NSURL does seem to be an infuriating class sometimes... :)

> My question here though would be is there any way of providing a
> clearer error message in ASIHTTPRequest?

I can see that you would have found this issue more quickly with a more informative error, but I'm not sure it's a good idea to get into sanity-checking the url ourselves (even assuming it isn't valid - again - I'm not sure). I could add a note to the description of the generic error you're seeing, but I imagine there are probably a lot of other reasons why the stream would fail to open, so the error message might end up being misleading.

Best,

Ben

Reply all
Reply to author
Forward
0 new messages