2010-10-14 75 views
1

我需要在python上創建.ASPXAUTH cookie。我編程到桌面客戶端。並且首先請求不需要.ASPXAUTH cookie但需要第二個請求。如何在python上創建.ASPXAUTH cookie

我的第一個請求報頭:

User-Agent: WebPolicy 
Host: xxx.host 
Cache-Control: no-cache 

我的第一個響應頭:

reply: 'HTTP/1.1 200 OK\r\n' 
header: Cache-Control: private 

header: Transfer-Encoding: chunked 

header: Content-Type: text/xml; charset=utf-8 

header: Server: Microsoft-IIS/7.5 

header: Set-Cookie: tivi_=3tnihi55ezuk50zyrrpuwv45; path=/; HttpOnly 

header: X-AspNet-Version: 2.0.50727 

header: X-Powered-By: ASP.NET 

header: Date: Thu, 14 Oct 2010 13:05:50 GMT 

,我需要第二發送標題:

Accept: */* 
Content-Length: 259 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://tempuri.org/IMiddlewareServices/Login" 
UA-CPU: x86 
Accept-Encoding: gzip, deflate 
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322) 
Host: mw.webtv.ttnet.com.tr 
Connection: Keep-Alive 
Cache-Control: no-cache 
Cookie: .ASPXAUTH=090F2718E32AF3F9B1C9E5A15BA54CFD8D4430C44A91029719953D4A6D38DD1D9164D86D772E2645C0C0545A71C12EA80AE5A8F725FD6037BD00DB291A863DD577735E16D8745E2833979F337935F29A37C509FB0350F1180DA0D2C1C44F97D0F081B13D33984C198ECD695C34B2E79A3E7CFBDD2D67D630C019714C3A70280E; tivi_=nqkngs45drnsh4z4y4b30g55 

請幫幫我!如何創建「.ASPXAUTH」cookie?

回答

0

Python請求模塊通過.ASPXAUTH基於cookie的身份驗證爲我完成這項工作。另外,在以下.ASPXAUTH一個簡單的例子 cookie被第一session.get呼叫之後接收和用於第二呼叫:

import requests 
session = requests.Session() 
session.get('https://host/user/login?username=###&password=###') 
print session.cookies 
session.get('https://host/apicall') 
print session.cookies