0

我正在使用 Python 语言中的 Locust 对象发送 http 请求(发布)。当我在一个 python 文件中使用 Locust 对象发送多个请求时,它可以工作,但是当我在单独的 python 文件中发送每个请求时,它不起作用,因为我收到会话过期消息。我们的要求是为每个请求使用单独的 python 文件,我想在其中读取上一个请求的会话并希望在下一个请求中分配该会话 ID。不知何故,我无法在下面的代码中做。有设置 cookie 的选项,但未在请求标头中设置。

subUrl='http://192.168.1.156:2016/login.aspx'
protocol='HTTP'
awaitingResponse = 1
response = self.client.post("http://192.168.1.156:2016/login.aspx", {"__EVENTTARGET":"","__EVENTARGUMENT":"","__LASTFOCUS":"","txtUserName":"Admin_Sample","txtPassword":"1","dllRole":"ProjectAdmin","cboProject":"Sample","Hdnlogin":"Please+enter+User+ID","HdnPassword":"Please+enter+Password","HdnProject":"Please+select+Project","HdnSubProject":"Please+select+Sub+Project","btnLogin":"Submit","__VIEWSTATE":VIEWSTATE1,"__VIEWSTATEGENERATOR":VIEWSTATEGENERATOR1},{"Cookie":""})

如果您能帮助我解决我的问题,我将不胜感激。

4

1 回答 1

0

您应该data使用您的数据进行设置,并且应该在内部发送 cookie,header如果需要,您可以设置用户代理。请参见下面的示例:

response = self.client.post("http://192.168.1.156:2016/login.aspx", headers = {"Cookie": "", 'User-Agent': "set_useragent"}, data = {"__EVENTTARGET":"","__EVENTARGUMENT":"","__LASTFOCUS":"","txtUserName":"Admin_Sample","txtPassword":"1","dllRole":"ProjectAdmin","cboProject":"Sample","Hdnlogin":"Please+enter+User+ID","HdnPassword":"Please+enter+Password","HdnProject":"Please+select+Project","HdnSubProject":"Please+select+Sub+Project","btnLogin":"Submit","__VIEWSTATE":VIEWSTATE1,"__VIEWSTATEGENERATOR":VIEWSTATEGENERATOR1})
于 2017-07-19T07:39:51.850 回答