python封装的GET&POST请求详解编程语言
2023-06-13 09:20:24 时间
httpClient.request("POST", path, params, headers)
response = httpClient.getresponse()
print response.status
print response.reason
print response.read()
print response.getheaders() #获取头信息
else:
print unsupport
except Exception, e:
print Exception, e
def get_page_content_by_requests(url, payload, timeout, headers, type = get): try: if type == get: response = requests.get(url, params=payload, timeout=timeout) response.encoding = gbk #设定编码 print response.status_code #返回状态 print response.text #返回字符结果 print response.content #返回二进制响应内容 print response.json() #获取Json响应内容 print response.raw #获取原始响应内容 print response.raise_for_status() #非200请况下抛出异常 print response.headers[Content-Type] #获取响应头某个字段 elif type == post: response = requests.post(url, data = json.dumps(payload), headers = headers, timeout=timeout) response.encoding = gbk #设定编码 print response.text else: print unsupport except Exception, e: print Exception, e
def get_page_content_by_requests(url, payload, timeout, headers, type = get): try: if type == get: response = requests.get(url, params=payload, timeout=timeout) response.encoding = gbk #设定编码 print response.status_code #返回状态 print response.text #返回字符结果 print response.content #返回二进制响应内容 print response.json() #获取Json响应内容 print response.raw #获取原始响应内容 print response.raise_for_status() #非200请况下抛出异常 print response.headers[Content-Type] #获取响应头某个字段 elif type == post: response = requests.post(url, data = json.dumps(payload), headers = headers, timeout=timeout) response.encoding = gbk #设定编码 print response.text else: print unsupport except Exception, e: print Exception, e
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/8245.html
cjava相关文章
- pycharm导入Python_python简单项目
- python中矩阵的转置怎么写_Python 矩阵转置的几种方法小结
- aic准则python_Python数据科学:线性回归
- python chmod_使Python脚本可执行chmod755?
- 谷歌是python开发的吗_google python
- lambda表达式python_Python中的Lambda表达式「建议收藏」
- Mac Python第三方库安装「建议收藏」
- python 图像处理库_Python图像处理库
- Python基础教程之循环
- 强化学习技巧五:numba提速python程序
- 新手学Python可行吗?需要什么基础?(新手学python可行吗?需要什么基础)
- 软件测试|Python基础之面向对象(一)
- Python如何获取页面上某个元素指定区域的html源码?
- Python赋值运算符(入门必读)
- Python的Mysql connector封装详解编程语言
- python:函数数据封装详解编程语言
- Python输出函数print()总结(python print())详解编程语言
- python之面向对象之封装详解编程语言
- Linux下的Python开发技术之旅(linux下python开发)