我正試圖在POST請求中添加一個文本變數,我希望得到一些建議,看看我可能做錯了什么。
原始代碼是在 html 中,但我想在 python 中使用它。
這里是原始的HTML:
< form name="channel327911" action="htps: //secure. logmeinrescue.com/Customer/Download.aspx"。
method="post"/span>>
<table>
<tr><td>請輸入你的名字。</td><td><。 input type="text" name="name" maxlength=
"64" /></td></tr>
</table>
< input type="submit" value="Channel 01" />
< input type="hidden" name="EntryID" value="327911" />
< input type="hidden" name="tracking0" maxlength="64" />
</form>
這是我的python代碼:
import requests
json_payload = {
"EntryID"。"327911",
"tracking0": "64".
}
requestlink = requests.post(url = "https://secure.logmeinrescue.com/Customer/Download.aspx"/span>, data = json_payload)
stuff = requestlink.content
用open("supportlmi.exe", 'wb') as s:
s.write(stuff)
問題是,如果我試影像這樣把name添加到帖子的正文中:
import requests
json_payload = {
"name": "Conglomo - Rocko"。
"EntryID": "327911",
"tracking0": "64".
}
requestlink = requests.post(url = "https://secure.logmeinrescue.com/Customer/Download.aspx"/span>, data = json_payload)
stuff = requestlink.content
用open("supportlmi.exe", 'wb') as s:
s.write(stuff)
然后它就會出錯。 我想一定有辦法把名字傳到正文中,因為你可以在html中使用表單來做這件事。
注意:你可以使用上面的HTML代碼,它應該能作業。我把它放在LOGMEIN的測驗支持組中,這樣你就可以在HTML中實際嘗試一下了。
編輯:結果應該是下載 Logmein 的啟動程式。而不是一個狀態代碼。
實際上,我找到了解決這個問題的方法 不要把name放在正文中,而是把名字附加到url本身,就像這樣;https://secure.logmeinrescue.com/Customer/Download.aspx?name=Conglomo Rocko這樣做,我不需要把名字放在正文中。結果是下載了Logmein的啟動器的exe檔案!
uj5u.com熱心網友回復:
這對我來說是有效的
import requests
payload = {
"EntryID"。"327911",
"tracking0": "64",
"name": "Conglomo - Rocko".
}
response = requests.post("https://secure.logmeinrescue.com/Customer/Download.aspx"/span>, json=payload)
東西 = 回應.內容
print(stuff)
print(response.status_code)
你需要將有效載荷作為json傳遞給請求
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/309491.html
標籤:
上一篇:從獲取的API資料串列中提取單個字串/Int-SwiftUI
下一篇:關閉按鈕c#Windows表單
