ytpm
ytpm

Reputation: 5150

ASIHTTPRequest error keeps appearing

I don't know why, but everything that I do wont help this issue. I just can't get the JSON data from the server.

This is the encoded NSString that I'm getting:

http%253A%252F%252Fwww.doctors.co.il%252Fmobile%252Fforum%252Fforum-4863%253Fpage%253D12%252F

This is my code:

- (NSString *)urlencode {
    NSMutableString *output = [NSMutableString string];
    const unsigned char *source = (const unsigned char *)[self UTF8String];
    int sourceLen = strlen((const char *)source);
    for (int i = 0; i < sourceLen; ++i) {
        const unsigned char thisChar = source[i];
        if (thisChar == ' '){
            [output appendString:@"+"];
        } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
                   (thisChar >= 'a' && thisChar <= 'z') ||
                   (thisChar >= 'A' && thisChar <= 'Z') ||
                   (thisChar >= '0' && thisChar <= '9')) {
            [output appendFormat:@"%c", thisChar];
        } else {
            [output appendFormat:@"%%%02X", thisChar];
        }
    }
    return output;
}

- (void)startLoadingApplicationDataOf
{
    NSString *raw = @"http://www.doctors.co.il/mobile/forum/forum-4863?page=12/";
    NSString *safestring = [raw urlencode];
    NSURL *requestURL = [NSURL URLWithString:safestring];
    [self startRequest:requestURL];
}

- (void)startRequest:(NSURL *)requestURL
{
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:requestURL];
    [request setDidFinishSelector:@selector(requestCompleted:)];
    [request setDidFailSelector:@selector(requestError:)];
    [request setDelegate:self];
    [request startAsynchronous];
    [request setTimeOutSeconds:20.0f];
}

What am I doing wrong? on other web address that return JSON, it works perfectly, but on this one I'm keep gettings this error:

Failed to load data with error: Error Domain=ASIHTTPRequestErrorDomain Code=6 "Unable to start HTTP connection" UserInfo=0x8bc72b0 {NSLocalizedDescription=Unable to start HTTP connection}

Upvotes: 0

Views: 1432

Answers (1)

ckhan
ckhan

Reputation: 4791

You have url-encoded your url, and no longer have a valid scheme (http:// gone, and what's left is http%25), which isn't going to load in a web browser, either, let alone a http library. You probably intended to URL-encode the query parameters. See http://en.wikipedia.org/wiki/Percent-encoding for more information.

Upvotes: 3

Related Questions