【发布时间】:2017-01-07 10:49:04
【问题描述】:
我在手机上使用了一个应用程序,它发送帖子请求并返回一些信息。我正在尝试从 Python 脚本模仿该发布请求,并获得相同的响应。
我使用数据包嗅探器查看请求是什么:
POST /b/ss/wdgwespmaflm/0/JAVA-4.10.0-AN/s23376784 HTTP/1.1
connection: close
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Linux; U; Android 5.1; en-US; HTC One_M8 Build/LMY47O.H4)
Accept-Language: en-US
Content-Length: 530
Host: w88.espn.com
Accept-Encoding: gzip
ndh=1&ce=UTF-8&vid=5f2c4950ca6e9359&pev2=ADBINTERNAL%3ALifecycle&c.&a.&DaysSinceFirstUse=52&RunMode=Application&HourOfDay=12&Resolution=1080x1776&DaysSinceLastUse=0&CarrierName=Partner&AppID=ESPN%20Fantasy%205.1.1%20%28155%29&TimeSinceLaunch=3&OSVersion=Android%205.1&PrevSessionLength=17&Launches=73&DeviceName=HTC%20One_M8&DayOfWeek=7&LaunchEvent=LaunchEvent&internalaction=Lifecycle&.a&.c&t=00%2F00%2F0000%2000%3A00%3A00%200%20-120&mid=61999711066602377445137974387884905365&pe=lnk_o&pageName=ESPN%20Fantasy%205.1.1%20%28155%29
我正在使用模块requests,我试过了
r = requests.post("http://w88.espn.com/b/ss/wdgwespmaflm/0/JAVA-4.10.0-AN/s23376784", headers={
'connection': 'close',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 5.1; en-US; HTC One_M8 Build/LMY47O.H4)',
'Accept-Language': 'en-US',
'Content-Length': '530',
'Host': 'w88.espn.com',
'Accept-Encoding': 'gzip'})
但脚本只是卡在请求上。我在哪里发送内容?
我不应该全部发送为headers 吗?我试过data,也没用。
有什么想法吗?
【问题讨论】:
-
首先,你的网址不完整“/b/ss/wdgwespmaflm/0/JAVA-4.10.0-AN/s23376784”,缺少协议和主机。
-
将
http://w88.espn.com/b/ss/wdgwespmaflm/0/JAVA-4.10.0-AN/s23376784用作URL -
啊好吧..我会试试的
-
仍然没有得到回复,
-
尝试将
ndh=1&ce=UTF-8&vid=5f2c4950ca6e9359&pev2=ADBINTERNAL%3ALifecycle&c.&a.& ...作为params参数添加到您的请求或添加到URL的末尾
标签: python python-2.7 http post python-requests