重置与AFNetworking基本身份验证凭据 [英] Resetting basic authentication credentials with AFNetworking

查看:232
本文介绍了重置与AFNetworking基本身份验证凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个REST客户端(与AFNetworking),需要触发一个应用程序的一个实例中一个新的会话创建能力。搜索结果换句话说,我想:结果
1 - 验证与服务器的结果
2 - 做一些REST调用结果
3 - 模拟退出结果
4 - 使用服务器的结果重新认证
5 - 做一些更多的REST调用搜索结果
AFNetworking是伟大的决策,初步验证和REST调用,但我想不通我怎么会清除会话和复位的同一个实例中的连接。搜索结果
当我用ASIHTTP,我只是做:结果
[ASIHTT prequest clearSession];搜索结果
有没有办法做AFNetworking类似的事情?_爱

I am writing a REST client (with AFNetworking) and need the ability to trigger the creation of a new session within a single instance of an application.

In other words, I would like to:
1 - Authenticate with server
2 - Do some REST calls
3 - Simulate "Log out"
4 - Re-authenticate with server
5 - Do some more REST calls

AFNetworking is great with making that initial authentication and REST calls, but I can't figure out how I would clear the session and "reset" the connection within the same instance.

When I used ASIHTTP, I just did:
[ASIHTTPRequest clearSession];

Is there a way to do something similar with AFNetworking?

推荐答案

使用 AFHTTPClient (见示例项目的API客户端)。

Use AFHTTPClient (see the API client in the example project).

凭据可设定 -setAuthorizationHeaderWithUsername:密码:。从HTTP客户端创建的每个请求将有一个授权 HTTP头,有点像一个浏览器会话。

Credentials can be set with -setAuthorizationHeaderWithUsername:password:. Each request created from that HTTP client will have an Authorization HTTP header, kind of like a browser session.

当用户注销,或要清除凭证,做 -clearAuthorizationHeader

When the user logs out, or you want to clear credentials, do -clearAuthorizationHeader.

这篇关于重置与AFNetworking基本身份验证凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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