# -*- 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)"}
# 使用requests库,返回结果错误
res = requests.post(url,data=jsonstr,headers = headers)
print res.text
# 使用httplib 返回结果正常
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()