1

I use MKNetwork Kit for this.

MKNetworkOperation *op = [[MKNetworkOperation alloc] initWithURLString:@"http://api.tumblr.com/v2/blog/my_blog.tumblr.com/avatar/512"
                                                                        params:nil
                                                                    httpMethod:@"GET"];

        [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
            UIImage *img = [completedOperation responseImage];
            DLog(@"%f x %f", img.size.height, img.size.width); //512 x 512
            NSFileManager *fileManager = [NSFileManager defaultManager];
            NSData *myImageData = UIImagePNGRepresentation(img);
        [fileManager createFileAtPath:@"/Users/Mac/Desktop/myimage.png" contents:img attributes:nil];
        } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
            DLog(@"error: %@",error);
        }];

   [self enqueueOperation:op];

And! Oh! wonderful Tumblr! I have an Image on my Desktop.

How can I prevent this behavior and change response to json with field avatar_url?

UPD:

Try this:

curl http://api.tumblr.com/v2/blog/my_blog.tumblr.com/avatar/512

And it will returns

{"meta":{"status":301,"msg":"Found"},"response":{"avatar_url":"good_link_here"}}

UPD 2:

Good answer
I must stop redirection.

4

0 に答える 0