如何发送Web请求 HTTP Get 在 Python?
我对网站发送数据并收到答案有任何问题 Python. 我已经看到了这样的问题,但他们似乎都没有达到我渴望的问题。
这是我的代码 C#, 我正在努力转移到 Python:
这是我的尝试 Python 年:
任何帮助将不胜感激!
这是我的代码 C#, 我正在努力转移到 Python:
static void Request/Uri selectedUri/
{
HttpWebRequest request = /HttpWebRequest/WebRequest.Create/selectedUri/;
request.ServicePoint.BindIPEndPointDelegate = BindIPEndPointCallback;
request.Method = "GET";
request.Timeout = /int/Timeout.TotalMilliseconds;
request.ReadWriteTimeout = /int/Timeout.TotalMilliseconds;
request.CachePolicy = CachePolicy;
request.UserAgent = UserAgent;
using /HttpWebResponse response = /HttpWebResponse/request.GetResponse///
{
using /StreamReader responseReader = new StreamReader/response.GetResponseStream////
{
string responseText = responseReader.ReadToEnd//;
File.WriteAllText/UrlFileName, responseText.Trim//, Encoding.ASCII/;
}
}
}
这是我的尝试 Python 年:
def request//:
web = httplib.HTTPConnection/'https://someurl.com'/;
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
web.request/"GET", "/heartbeat.jsp", headers/;
response = web.getresponse//;
stream = ""; #something is wrong here
任何帮助将不胜感激!
没有找到相关结果
已邀请:
2 个回复
风见雨下
赞同来自:
http://docs.python.org/2/library/urllib2.html
你也可以使用
http://docs.python.org/2.6/library/httplib.html
或者
http://docs.python-requests.org/en/latest/
卫东
赞同来自:
/
http://docs.python.org/2/library/urllib2.html
/, 为您制定所有这些工作。
简单得多:
打印收到 HTTP 回答。
转移参数 GET / POST 您可以使用该功能
. 有关更多信息,您可以联系
http://docs.python.org/2/howto/urllib2.html