转载:python发送HTTP请求
1. [代码]GET 方法
import httplib
#-----------------------------
conn = httplib.HTTPConnection("www.python.org")
conn.request("GET", "/index.html")
r1 = conn.getresponse()
print r1.status, r1.reason
06 200 OK
data1 = r1.read()
conn.request("GET", "/parrot.spam")
r2 = conn.getresponse()
print r2.status, r2.reason
404 Not Found
data2 = r2.read()
conn.close()
2. [代码]HEAD 方法
import httplib
#-----------------------------
conn = httplib.HTTPConnection("www.python.org")
conn.request("HEAD","/index.html")
res = conn.getresponse()
print res.status, res.reason
06 200 OK
data = res.read()
print len(data)
09 0
data == ''
True
3. [代码]POST 方法
import httplib, urllib
#-----------------------------
params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
headers = {"Content-type": "application/x-www-form-urlencoded",
... "Accept": "text/plain"}
conn = httplib.HTTPConnection("musi-cal.mojam.com:80")
conn.request("POST", "/cgi-bin/query", params, headers)
response = conn.getresponse()
print response.status, response.reason
09 200 OK
data = response.read()
conn.close()a
转载:python发送HTTP请求的更多相关文章
- python发送post请求上传文件,无法解析上传的文件
前言 近日,在做接口测试时遇到一个奇葩的问题. 使用post请求直接通过接口上传文件,无法识别文件. 遇到的问题 以下是抓包得到的信息: 以上请求是通过Postman直接发送请求的. 在这里可以看到消 ...
- Python发送http请求时遇到问题总结
1.报错信息为“ERROR 'str' object has no attribute 'endwith'”,排查发现endswith方法名写错了,少了s,写成了 'endwith' if inter ...
- python发送网络请求
1.使用urllib模块(使用不方便,建议使用第二种) get请求: res = urlopen(url) from urllib.request import urlopen url = 'http ...
- python发送requests请求时,使用登录的token值,作为下一个接口的请求头信息
背景介绍: 发送搜索请求时,需要用到登录接口返回值中的token值 代码实现: 登录代码: 搜索接口:
- requests模块--python发送http请求
requests模块 在Python内置模块(urllib.urllib2.httplib)的基础上进行了高度的封装,从而使得Pythoner更好的进行http请求,使用Requests可以轻而易举的 ...
- python发送post请求
urllib2.urlopen() urlib2是使用各种协议完成打开url的一个扩展包.最简单的使用方式是调用urlopen方法,比如 def urlopen(url, data=None, tim ...
- python 发送POST请求
#博客地址:https://blog.csdn.net/qq_36374896 import urllib.request import urllib.parse url = "http:/ ...
- python 发送GET请求
# #博客地址:https://blog.csdn.net/qq_36374896 # 特点:把数据拼接到请求路径的后面传递给服务器 # # 优点:速度快 # # 缺点:承载的数据量小,不安全 imp ...
- 转载---HttpUrlConnection发送post请求汉字出现乱码的一个解决方法及其原因
原文:http://blog.csdn.net/qqaazz211/article/details/52136187 在网上看到了这篇比较简单的解决方法,果然有用,特记之 解决方法是:将 out.wr ...
随机推荐
- 常用js函数整理--common.js
var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data: data, dataType: 'json ...
- MySQL应用的异常记录
>>Error Code: 1045. Access denied for user 'test'@'%' (using password: YES) 使用MySQL的select * i ...
- JavaWeb学习之什么是Servlet、如何使用servlet、为什么这样使用、servlet的虚拟路径、关于缺省Servlet(2)
1.什么是Servlet? * 服务器端Java程序,servlet需要交给服务器来运行. * 与javax.servlet.Servlet接口有关的java程序 2.如何使用servlet?[必须] ...
- 在Eclipse中自定义类似syso的快捷代码模板
sysout/syso syserr/ syse 点击菜单栏的“Window”->“Preferences”,打开“Preferences”对话框.在Preferences”对话框中点击“Jav ...
- 【转载】 Python动态生成变量
用Python循环创建多个变量, 如创建 a1= .a2= .a3= .a4= .a5= 或 self.a1= .self.a2= . self.a3= 一. 可以通 ...
- [LeetCode] Pow(x, n)
Implement pow(x, n). 有史以来做过最简单的一题,大概用5分钟ac,我采用fast exponential,这个在sicp的第一章就有描述.思想是:如果n是偶数的话,那么m^n = ...
- C# 令某个窗体可跟着鼠标移动
/// <summary> /// 使窗口的中的指定控件支持运行时移动 /// TODO:运行时缩放 /// </summary> public class ControlMo ...
- cocos2d-x CCScrollView和CCTableView的使用(转载)
转载请注明来自:Alex Zhou的程序世界,本文链接:http://codingnow.cn/cocos2d-x/1024.html //============================== ...
- Android使用JNI实现Java与C之间传递数据(转)
介绍Java如何将数据传递给C和C回调Java的方法. java传递数据给C,在C代码中进行处理数据,处理完数据后返回给java.C的回调是Java传递数据给C,C需要用到Java中的某个方法,就需 ...
- C# 指针操作图像 二值化处理
/// <summary> /// 二值化图像 /// </summary> /// <param name="bmp"></param& ...