我正在使用 Rails 服务器,并且我有一个带有 Restkit 的应用程序来访问服务器。
我的服务器使用会话 cookie 登录。当我在 /sessions 中发布我的帐户信息时,我登录了,我可以从服务器访问私人区域。问题是,我不想在想使用该应用程序时登录。我不知道 restkit 如何处理 cookie,但是当我的会话“打开”时,我不需要担心它。但现在我想使用我的 cookie 访问私人区域。
当我登录时:
'POST /sessions HTTP/1.1
Host: localhost:3000
Accept-Encoding: gzip, deflate
Content-Type: application/json
Content-Length: 74
Accept-Language: en-us
Accept: application/json
Connection: keep-alive
User-Agent: TicketIn/1.0 CFNetwork/609.1.4 Darwin/11.4.2
{"session":{"email":"***","password":"***"}}'
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Ua-Compatible: IE=Edge
Etag: "7215ee9c7d9dc229d2921a40e899ec5f"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 41f0c482720d6cdcedb64071a6ebf9e7
X-Runtime: 0.222790
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
Date: Wed, 26 Jun 2013 13:23:28 GMT
Content-Length: 1
Connection: Keep-Alive
Set-Cookie: _vitrine_session=*session*; path=/; HttpOnly
当我尝试访问私人区域时:
GET /ingressos HTTP/1.1
Host: localhost:3000
If-None-Match: "310fd8ebf912d0633caa05a91ce56fcc"
Accept-Encoding: gzip, deflate
Accept: application/json
Cookie:
_vitrine_session=*session*
Content-Length: 0
Accept-Language: en-us
Connection: keep-alive
User-Agent: TicketIn/1.0 CFNetwork/609.1.4 Darwin/11.4.2
但是当我尝试在没有先登录的情况下访问私人区域时:
GET /ingressos HTTP/1.1
Host: localhost:3000
Accept-Encoding: gzip, deflate
Accept: application/json
Content-Length: 0
Connection: keep-alive
Accept-Language: en-us
User-Agent: TicketIn/1.0 CFNetwork/609.1.4 Darwin/11.4.2
那么如何在我的 http 请求中包含 cookie?
谢谢!