-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
288 additions
and
243 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
__author__ = 'Administrator' | ||
from COMMON.BaseGoals import Goals as go | ||
|
||
# 参数化请求 | ||
def str__post_param(list_param): | ||
result = {} | ||
for i in list_param: | ||
result[i["name"]] = i["value"] | ||
return result | ||
class chttp_params(): | ||
def __init__(self): | ||
pass | ||
# post参数化 | ||
def str__post_param(self, list_param): | ||
result = {} | ||
for i in list_param: | ||
if i["must"] == "1": # 如果参数是必填 | ||
result[i["name"]] = self.str_to(i["type"], i["value"]) | ||
return result | ||
# get 参数化,param是dict | ||
def str_get_param(self, dict_param, param): | ||
result = "?" | ||
if dict_param["must"] == "1": # 如果参数是必填 | ||
result += dict_param["name"] + "=" + dict_param["value"] + "&" | ||
# result += dict_param["name"] + "=" + str(self.str_to(dict_param["type"], dict_param["value"])) + "&" | ||
return self.str_sub(0, len(result)-1, result) + "&" + self.for_dict(param) | ||
# 合并dict | ||
def for_dict(self, d): | ||
result = "" | ||
for (k, v) in d.items(): | ||
result += str(k) + "=" + str(v) | ||
return result | ||
# 截取str | ||
def str_sub(self, start, end, str): | ||
return str[start:end] | ||
# 转换类型 | ||
def str_to(self, type, s): | ||
elements = { | ||
go.INT: lambda: int(s), | ||
go.STR: lambda: s, | ||
go.FLOAT: lambda: float(s) | ||
} | ||
return elements[type]() | ||
|
||
def str_get_param(list_param, param): | ||
result = "?" | ||
result += list_param["name"] + "=" + list_param["value"] + "&" | ||
return str_sub(0, len(result)-1, result) + "&" + for_dict(param) | ||
|
||
def for_dict(d): | ||
result = "" | ||
for (k, v) in d.items(): | ||
result += str(k) + "=" + str(v) | ||
return result | ||
|
||
def str_sub(start, end, str): | ||
return str[start:end] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'Administrator' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
__author__ = 'Administrator' | ||
# -*- coding:utf-8 -*- | ||
import requests | ||
import ast | ||
import json | ||
|
||
class ConfigHttp(): | ||
def __init__(self, mhttpbase): | ||
self.mhttpbase = mhttpbase | ||
def get(self, url, params): | ||
result = {} | ||
url = "http://" + self.mhttpbase.host + ":" + self.mhttpbase.port + "/" + url + params | ||
print(url) | ||
try: | ||
r = requests.get(url, headers={'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | ||
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0'}) | ||
r.encoding = 'UTF-8' | ||
return r.text | ||
except Exception: | ||
print('no json data returned') | ||
return {} | ||
r = requests.get(url, headers=ast.literal_eval(self.mhttpbase.header)) | ||
r.encoding = 'UTF-8' | ||
if r.status_code == 200: | ||
result = json.loads(r.text) | ||
result["status_code"] = r.status_code | ||
print(result) | ||
return result | ||
|
||
# 封装HTTP POST请求方法,支持上传图片 | ||
def post(self, url, files=None, data=None): | ||
# data = eval(data) | ||
url = 'http://' + self.mhttpbase.host + ':' + self.mhttpbase.port + "/" + url | ||
r =requests.post(url, files=files, data=data) | ||
json_response = r.text | ||
print(json_response) | ||
return json_response | ||
print(url) | ||
r = requests.post(url, files=files, data=data) | ||
result = {} | ||
if r.status_code == 200: | ||
result = json.loads(r.text) | ||
result["status_code"] = r.status_code | ||
print(result) | ||
return result |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters