AFNetworking-获取重定向URL [英] AFNetworking -- get redirect URL

查看:100
本文介绍了AFNetworking-获取重定向URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对REST API使用AFNetworking。

Use a AFNetworking against a REST API.


  • POST到资源/

  • 服务器响应与303->请参阅resources / 3928.json

服务器在此处提供信息:id 3928 已分配给您的资源。

The the server is giving information here: the id 3928 has been assigned to your resource.

在POST操作期间是否可以学习此URL?另外,我真的不需要此资源。我可以避免实际执行重定向吗?

Is it possible to learn this URL during the POST operation? Also, I don't really need this resource. Can I avoid actually following the redirect?

另一种选择是将200与 {status: ok,insert_id:3928}一起使用,但感觉没有必要

Another option is to use a 200 with {status:"ok",insert_id:3928} but it feels like this is not necessary

推荐答案

-(void)call
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:YOUR_PARAMETER forKey:KEY];

    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:YOUR_WEBSERVICE_URL];
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:WEBSERVICE_NAME parameters:params];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    [httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         //This is Redirect URL 
         NSLog(@"%@",[[[operation response] URL] absoluteString]);
     } failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"Failure");
     }];

     [operation start];
}

这篇关于AFNetworking-获取重定向URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆