import json

import requests

default_headers = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 ' \
                  'Safari/537.36 '


def http_get(url):
    rsp = requests.get(url, proxies={'http': '', 'https': ''}).text
    json_data = json.loads(rsp)
    return json_data


def http_put(url, data):
    # 必须指定Content-Type为application/json才能成功请求
    headers = {'User-Agent': default_headers,
               "Content-Type": "application/json"}
    rsp = requests.put(url, data=data, headers=headers)
    return rsp


def http_post(url, data):
    headers = {'User-Agent': default_headers, "Content-Type": "application/json"}
    rsp = requests.post(url, data=data, headers=headers)
    return rsp


if __name__ == '__main__':
    sensitive_ship_query_api = 'http://47.115.228.133:28081/api/open/sensitiveTarget/query'
    query_data_body = {
        "targetType": "ship",
        "delFlag": "0"
    }
    sensitive_target_info = http_post(sensitive_ship_query_api, json.dumps(query_data_body))
    rsp_body = json.loads(sensitive_target_info.text)
    if rsp_body['code'] == 200:
        sensitive_target_list = rsp_body['content']
        sensitive_target_count = int(rsp_body['message'])
    pass
