Objective C コードから特定の URL への Http GET 要求をセットアップしようとしています。何をしても、どの URL を使用しても、次のエラーが表示されます。
Connection Failed: Error Domain=NSURLErrorDomain
Code=-1000 "bad URL" UserInfo=0x755c440
{NSUnderlyingError=0x7561950 "bad URL", NSLocalizedDescription=bad URL}
私は iOS 開発に不慣れなので、これを正しく行っているかどうかはわかりません。Apple のドキュメントに従い、さまざまなフォーラムで回答を探しましたが、それでもこのエラーが発生します。
これが私のコードです:
NSString *url = [NSString stringWithFormat: @"http://example.com/api/%@/%@", str1, str2];
NSString *encodedUrl = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSLog(@"URL - %@", encodedUrl); // Checking the url
NSMutableURLRequest *theRequest= [[NSMutableURLRequest alloc] init];
[theRequest setHTTPMethod:@"GET"];
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:encodedUrl]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
どんな提案でも大歓迎です。