Objective c ASIHTTPRequest错误不断出现
我不知道为什么,但我所做的一切都无助于解决这个问题。我只是无法从服务器获取JSON数据 这是我得到的编码NSString:Objective c ASIHTTPRequest错误不断出现,objective-c,ios,json,request,asihttprequest,Objective C,Ios,Json,Request,Asihttprequest,我不知道为什么,但我所做的一切都无助于解决这个问题。我只是无法从服务器获取JSON数据 这是我得到的编码NSString: http%253A%252F%252Fwww.doctors.co.il%252Fmobile%252Fforum%252Fforum-4863%253Fpage%253D12%252F 这是我的代码: - (NSString *)urlencode { NSMutableString *output = [NSMutableString string];
http%253A%252F%252Fwww.doctors.co.il%252Fmobile%252Fforum%252Fforum-4863%253Fpage%253D12%252F
这是我的代码:
- (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];
}
您已经用url编码了url,并且不再有有效的方案(http://gone,剩下的是
http%25
),该方案也不会加载到web浏览器中,更不用说http库了。您可能打算对查询参数进行URL编码。有关详细信息,请参阅。您的url已编码,并且不再具有有效的方案(http://gone,剩下的是http%25
),该方案也不会加载到web浏览器中,更不用说http库了。您可能打算对查询参数进行URL编码。有关更多信息,请参阅
Failed to load data with error: Error Domain=ASIHTTPRequestErrorDomain Code=6 "Unable to start HTTP connection" UserInfo=0x8bc72b0 {NSLocalizedDescription=Unable to start HTTP connection}