我可以使用curl访问webservice,如下所示
curl -k -u "admin:password" "https://10.184.39.12:8080/mypage/managed/user?_query=query-all"
我想通过python代码访问它。我可以用httplib。
connection.request("GET",url,params,headers)-k,-u "admin:password"是标题。请帮帮忙。
发布于 2015-12-08 13:14:11
您需要将用户名和密码编码为base64,并将其添加到标头中。就像这样:
import base64
import string
import httplib
auth = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
webservice = httplib.HTTP(host)
webservice.putheader("Authorization", "Basic %s" % auth)
# Add other headers etc在这篇博文中有更多的信息:http://mozgovipc.blogspot.nl/2012/06/python-http-basic-authentication-with.html
https://stackoverflow.com/questions/34156549
复制相似问题