我正在尝试对Web服务器进行POST。我有想要在正文和标题中发布的数据(直接从Chrome中获取)。没有太多细节,当我明确设置标题时,我得到400响应代码。
# Explicitly set headers causes 400 response
req = requests.post(url, auth_form, headers=authenticate)
print(req.status_code)
但是以下内容会返回200响应代码:
# Setting data as my form to post and headers as json
# Returns a 200 response code
req = requests.post(url, auth_form, authenticate)
print(req.status_code)
我正在尝试通过代码模拟登录。即使我收到200响应,我也没有成功登录。我怀疑这是因为我没有正确设置标题,但我不确定。
我实际上能够完全删除标题(作为headers =或json)并仍然收到200响应代码。我相信这强化了标题没有正确设置的想法。
# Removing headers entirely
# Returns a 200 response code
req = requests.post(url, auth_form)
print(req.status_code)
我不确定是否需要其他详细信息(例如某些标题)。如果是这样,我将尽可能多地提供这些信息。
编辑:标题,按要求:
authenticate = {}
authenticate["Accept"] = accept
authenticate["Accept-Encoding"] = "gzip, deflate, br"
authenticate["Accept-Language"] = "en-US,en;q=0.8"
authenticate["Cache-Control"] = "max-age=0"
authenticate["Connection"] = "keep-alive"
authenticate["Host"] = dns + ":" + str(port)
authenticate["Origin"] = "http://" + dns + ":" + str(port)
authenticate["Referer"] = "http://" + dns + ":" + str(port) + "/eproc/"
authenticate["Upgrade-Insecure-Requests"] = upgrade_insecure
authenticate["Cookie"] = "ID=" + self.session_id
authenticate["User-Agent"] = user_agent
auth_form = {}
auth_form["username"] = username
auth_form["password"] = password