码迷,mamicode.com
首页 > 编程语言 > 详细

httpUtils python

时间:2019-10-09 19:34:04      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:agent   strong   ams   htm   roi   table   store   import   tty   

依赖:

pip install requests 

 

#coding=utf8
import requests
# from common.logger import Logger
# import logging
class httpUtils:
#     logger = Logger("../logs/http.log",logging.INFO,logging.INFO)
    def get(self,url,params={},headers={}):
        res = requests.get(url,data=params,headers=headers)
     
        
        print("请求路径:" + res.request.url)
        headerStr = ""
        for headerKey in res.request.headers:
            headerStr = headerStr + "\n" + headerKey + ":" + res.request.headers[headerKey]
        print("请求头信息:" + headerStr)
        print("请求参数:\n" + res.request.body)

        resHeaderStr = ""
        for resHeaderKey in res.headers:
            resHeaderStr = resHeaderStr + "\n" + resHeaderKey + ":" + res.headers[resHeaderKey]
        print("响应头信息:" + resHeaderStr)
        print("返回结果:\n" + res.content.decode("utf-8"))
        return res
    
    def post(self,url,params={},headers={}):
        res = requests.post(url,data=params,headers=headers)
        print("请求路径:"+res.request.url)
        headerStr = ""
        for headerKey in res.request.headers:
            headerStr =headerStr+ "\n" + headerKey + ":" + res.request.headers[headerKey]
        print("请求头信息:" + headerStr)
        print("请求参数:\n"+res.request.body)

        resHeaderStr = ""
        for resHeaderKey in res.headers:
            resHeaderStr =resHeaderStr+ "\n" + resHeaderKey + ":" + res.headers[resHeaderKey]
        print("响应头信息:"+resHeaderStr)
        print("返回结果:\n"+res.content.decode("utf-8"))
        return res

 

 

使用:

 

#encoding=utf-8
‘‘‘
Created on 2019??10??9??
@author: sea
‘‘‘
# from com.sea.hhtp.MyHttp import get, post
from com.sea.hhtp import httputils



print("###################################################")
print("###################################################")
print("################       GET     ####################")
print("###################################################")
print("###################################################")
headers = { 
            "user-agent"  : "ad", 
            "Appstore-clientType" : "android", 
            "Appstore-IMEI" : "123456789000000"
            } 

getheader={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}
getresult =httputils.get("http://192.168.18.129:7016/worktable?page=1&size=2")
print(str(getresult))
print("13213")
print("13213")




print("###################################################")
print("###################################################")
print("################       POST     ###################")
print("###################################################")
print("###################################################")



postresult = httputils.post("http://192.168.18.129:7016/worktable/dynamicQueryWithPage",{"status":"CCD","page":1,"size":2},{"Content-Type":"application/json"})
print(str(postresult))

 

 

 

 

 

使用:

httpUtils python

标签:agent   strong   ams   htm   roi   table   store   import   tty   

原文地址:https://www.cnblogs.com/lshan/p/11643478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!