我需要非常重要的时间(以毫秒为单位,并且需要非常快速地发送json请求)插座非常快我通过套接字发送数据,但是在等待运行脚本后无响应
代码
import socket
import time
import ssl
start_time1 = time.time()
target_host = "site.com"
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
target_port = 443 # create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(( target_host,443 ))
s = context.wrap_socket(s,server_hostname=target_host)
request = "POST /api/send HTTP/1.1\r\nHost:site.com\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0\r\nCookie: .ASPXAUTH=D6CA254ED2327019933D1746092C47DD2884398658FF3DCAD213B8B9F0F73F7A67BC0C483F316F76195B49BC2C487783F9C73009B3469F1F7BCE6286C6C16A45916A013285E23808DED1C2F8E65262C377923823B538CFCC;\r\n{'IsSymbolCautionAgreement': 'false', 'CautionAgreementSelected': 'false', 'IsSymbolSepahAgreement': 'false', 'SepahAgreementSelected': 'false', 'orderCount': 112, 'orderPrice': 45150, 'FinancialProviderId': '1', 'minimumQuantity': '', 'maxShow': '0', 'orderId': '0', 'isin': 'IRO7NIRP0001', 'orderSide': '65', 'orderValidity': '74', 'orderValiditydate': 'null', 'shortSellIsEnabled': 'false', 'shortSellIncentivePercent': '0'}"
s.send(request.encode())
response = s.recv( 9999 )
s.close()
print request
print response + '\n'
print("--- %s seconds-total ---" % (time.time() - start_time1))