相关疑难解决方法(0)

如何使用AFNetworking为"PUT"请求设置数据?

我已经开始使用AFNetworking,它可以很好地进行简单的"GET"请求.但是现在我正在尝试进行"POST" - 请求.我使用下面的代码来执行"GET"请求.在查看AFHTTPClientputhPath时,无法设置要用于正文的数据.我的猜测是,有另一种解决方法.我一直在关注AFHTTPOperation作为解决这个问题的方法.但是,我没有让这个工作.问题是我不知道如何在基本身份验证中使用它.

有人可以给我一个如何用AFNetworking做一个简单的"POST"请求的提示吗?

AFHTTPClient* client = [AFHTTPClient clientWithBaseURL:ServerURL];
[client setAuthorizationHeaderWithUsername:self.username 
                                  password:self.password];

NSString* resourcePath = [NSString stringWithFormat:@"/some/resource/%@", 
                          endPath];

[client getPath:resourcePath 
     parameters:nil 
        success:^(AFHTTPRequestOperation *operation, id responseObject) {
            // Success code omitted
        } 
        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            // Some error handling code omitted
        }
 ];
Run Code Online (Sandbox Code Playgroud)

iphone http objective-c ios afnetworking

2
推荐指数
1
解决办法
8406
查看次数

标签 统计

afnetworking ×1

http ×1

ios ×1

iphone ×1

objective-c ×1