Python implements a simple HTTP POST function

 Python implements a simple HTTP POST function

import requests

def httpPost(url, msg):
    httpHeader = {"Content-Type": "application/json"}
    resp = requests.post(url, headers=httpHeader, data=str(msg), timeout=(3,10))
    if 200 == resp.status_code:
        return True
    else:
        return False
        
ps: When using the requests library post, you must set the timeout, otherwise it will block, that is, stuck

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example