0

アプリで遅延読み込みが必要なので、ご覧のとおり NSURLConnection を使用して画像をダウンロードしています

premiumRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"www.aaaaaaaaa.com/aaaaaaaaa/api/uploads/company_logo/cc2ab63fd3eb564be64b4f21bd083bc7.png"]
                   cachePolicy:NSURLRequestUseProtocolCachePolicy
                timeoutInterval:60.0];

premiumConnection=[[NSURLConnection alloc] initWithRequest:premiumRequest delegate:self];

しかし、残念ながら次のエラーが発生します

error downloading: unsupported URL

ブラウザに URL を貼り付けるとうまく動作しますが、 NSURLConnection では動作しません。上記の URL の問題を解決してください

4

3 に答える 3

3

URL に適切な URL スキームを含めるようにしてください。

...[NSURL URLWithString:@"http://www...
于 2012-05-02T07:15:33.900 に答える
1
NSURL *url = [NSURL URLWithString:@"http://www.invoicera.com/app/api/check_json_api.php?token=CFBF57B78FB183157BF93F0EB00C9C33"];

NSString *jsonRequest = [NSString stringWithFormat:@"&json_data=%@",[[NSString stringWithFormat:@"yourString"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSLog(@"%@",jsonRequest);

NSData *json_data = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];

NSLog(@"The converted String is %@",json_data);

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];


[request setHTTPMethod:@"POST"];
[request setHTTPBody: json_data];
NSLog(@"%@",json_data);
// [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [json_data length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:[[jsonRequest stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]
                      dataUsingEncoding:NSUTF8StringEncoding 
                      allowLossyConversion:YES]];

// [NSURLConnection connectionWithRequest:[自動解放のリクエスト] delegate:self];

NSURLConnection *nsUrlConnection=[[NSURLConnection alloc]
                                  initWithRequest:request 
                                  delegate:self];

// Successful connection.
if (nsUrlConnection) {

    [self indicatorView];
   // [self initSpinner];
   // [self spinBegin];

    NSMutableData *data = [[NSMutableData alloc] init];
    self.receivedData=data;
    [data release];
} 
// Unsuccessful connection.
else {

}  
// Clean up
[url release];
[request release];

その後、プロパティを適切に設定すると、エラーが発生します。

回答の上矢印を押して、回答に投票します。

于 2012-05-02T07:18:37.860 に答える
0
    NSURL *webURL = [NSURL URLWithString:@"あなたの URL はこちら"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:webURL];
    [request setTimeoutInterval:60.0];
    [request setHTTPMethod:aStrGetOrPost];
    NSError *エラー;
    NSURLResponse *応答;

    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returnedResponse:&response エラー:&error];

    if(データを返す)
        {
            // データに対してやりたいことを行う
        }
        そうしないと
        {
            //失敗アラートを表示する
        }

于 2012-05-02T07:18:01.653 に答える