def send_sync_request(url, headers=None, method="GET", body=None):
headers = headers or {}
if body or method.upper() == "POST":
if "Content-Type" not in headers:
headers["Content-Type"] = "application/x-www-form-urlencoded"
req = httpclient.HTTPRequest(
url, method=method, body=body, headers=headers, allow_nonstandard_methods=True)
http_client = httpclient.HTTPClient()
response = ""
try:
response = http_client.fetch(req)
return response
except httpclient.HTTPError as e:
print("Error:" + str(e))
raise httpclient.HTTPError()
except Exception as e:
print("Error:" + str(e))
raise Exception
finally:
http_client.close()
评论列表
文章目录