假设我有一种方法可以将http 请求发送到服务器。如何同时向服务器发送两个(或更多)请求?例如,也许通过分叉一个进程?我该怎么做?(我也在使用 django)
#This example is not tested...
import requests
def tester(request):
server_url = 'http://localhost:9000/receive'
payload = {
'd_test2': '1234',
'd_test2': 'demo',
}
json_payload = simplejson.dumps(payload)
content_length = len(json_payload)
headers = {'Content-Type': 'application/json', 'Content-Length': content_length}
response = requests.post(server_url, data=json_payload, headers=headers, allow_redirects=True)
if response.status_code == requests.codes.ok:
print 'Headers: {}\nResponse: {}'.format(response.headers, response.text)
谢谢!