有了curl,我就可以登录了。在
curl 'https://server.com/server.jsp?login' --data 'username=usernamex&PASSWORD=contrase%F1a'
contrase%F1a15表示“contraseña15”
但当我试图发送相同的内容与请求,我收到的密码是不正确的。在
^{pr2}$我怎么能解决这个问题?我尝试了几种选择。比如payload={'password':'contraseña15”.}并使用json.dumps文件,但什么都没有,我总是得到同样的结果。在
请帮忙!在
编辑: 我也试过这个
import urllib2, urllib
url = 'https://server.com/server.jsp?login'
data = urllib.urlencode({'USUARIO':'username','PASSWORD':'contrase%F1a15'})
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
d = response.read()
print d
什么也没有,我也得到同样的结果。只适用于卷曲。在
编辑2:
额外的东西
我收到了和请求一样的结果
curl 'https://server.com/server.jsp?login' --data 'USUARIO=username&PASSWORD=contraseña15'
但如果我用这个!工作出色。在
curl 'https://server.com/server.jsp?login' --data 'USUARIO=username&PASSWORD=contrase%F1a15'
编辑3:
有了PyCurl就完美了!在
import pycurl
c = pycurl.Curl()
c.setopt(c.URL, 'https://server.com/server.jsp?login')
postfields = 'USUARIO=username&PASSWORD=contrase%F1a15'
c.setopt(c.VERBOSE, True)
c.setopt(c.POSTFIELDS, postfields)
c.perform()
c.close()
终于来了!谢谢@mhawke
解决方案:
login_url = 'https://server.com/server.jsp?login'
password = u'contraseña15'.encode('iso-8859-1')
payload = {'username': 'usernamex', 'PASSWORD': password}
r = requests.post(login_url, data=payload)
我的最后一次复习。 相同的URL和相同的POST数据。 With requests不起作用,但在pycurl中有效。在
尝试按如下方式发布未编码的值:
^{pr2}$requests
将为您处理url编码。服务器应该看到在柱子上。在
更新
使用
curl
时,所发布的数据似乎是url编码的ISO-8859-1文本或类似文本。使用requests
,发布的数据是urlencoded UTF8数据。服务器似乎希望请求主体使用ISO-8859-1编码。试试这个:通过此请求,服务器现在应该看到:
与
curl
生成的相同。在我在我的系统里试过了,这个东西成功了:
我输入的密码与我在表格中输入的密码完全相同。它对我有效,我得到了
response code of 200
。在相关问题 更多 >
编程相关推荐