curl Web サービスからデータを取得したいのですが、コードが機能しません
NSURL *url = [NSURL URLWithString:delegate.profilePic]; NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:picUrl]; [req setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [req setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"]; NSString *token =delegate.Token; [req setValue:token forHTTPHeaderField:@"X-Auth-Token"]; [req setHTTPMethod:@"GET"]; NSError *error = nil; NSURLResponse *response; NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error]; NSString *myString = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(@"Url Data %@",myString);
質問する
137 次
1 に答える
0
このコードを試してみてください。これを使用して画像データを取得しました
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSURL *url = [NSURL URLWithString:delegate.profilePic];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
[req setHTTPMethod:@"GET"];
NSString *boundary = @"0x0hHai1CanHazB0undar135";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[req addValue:contentType forHTTPHeaderField: @"Content-Type"];
[req setValue:delegate.Token forHTTPHeaderField:@"X-Auth-Token"];
NSError *error = nil;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
dispatch_sync(dispatch_get_main_queue(), ^{
profilePicView.image=[UIImage imageWithData:urlData];
});
});
于 2013-10-10T09:35:12.140 に答える