亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

同樣的參數使用requests庫得不到返回結果,而httplib可以正確返回??赡艿脑蚴鞘裁矗?/h1>

# -*- coding: utf-8 -*-

import requests
import json

url = 'http://www.demodemo.cc/rpc/IUserService'
params = {
? ?"jsonrpc": "1.1",
? ?"method": "getAllMyRecommend_v2_3",
? ?"id": {"sid": "jgjycleypyvciibjupanfmbpplyibvsr", "sign": "d41d8cd98f00b204e9800998ecf8427e", "uid": 17139,
? ? ? ? ? "cVer": "21"},
? ?"params": [17139, 0, 10]
}

jsonstr = json.dumps(params)
headers = {"Content-type": "application/json", "Accept": "application/json",
? ? ? ? ? "Connection": "Keep-Alive",
? ? ? ? ? "User-Agent": "MusicSample/2.4.2 (iPhone; iOS 9.2; Scale/3.00)"}
# use httplib can not ?get correct response
res = requests.post(url, data=jsonstr, headers=headers)
print res.text

# use httplib can get correct response
import httplib

httpClient = None
try:
? ?httpClient = httplib.HTTPConnection("www.demodemo.cc", 80, timeout=30)
? ?httpClient.request(method="POST", url="/rpc/IUserService", body=jsonstr, headers=headers)

? ?response = httpClient.getresponse()
? ?print response.status
? ?print response.reason
? ?print response.read()
? ?print response.getheaders() ?# huoqu header
except Exception, e:
? ?print e
finally:
? ?if httpClient:
? ? ? ?httpClient.close()



正在回答

0 回答

舉報

0/150
提交
取消
初識Python
  • 參與學習       758392    人
  • 解答問題       8967    個

學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序

進入課程

同樣的參數使用requests庫得不到返回結果,而httplib可以正確返回??赡艿脑蚴鞘裁??

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號