Home > Net >  API postpayload include text variables
API postpayload include text variables

Time:09-17

I am trying to add a text variable to a POST request and I wanted some suggestions on what I could be doing wrong.

The original code is in html, but I want to use it in python.

Here is the original HTML:

<form name="channel327911" action="https://secure.logmeinrescue.com/Customer/Download.aspx"
 method="post">
    <table>
        <tr><td>Please enter your name: </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>

Here is my python code:

import requests

json_payload = {
"EntryID": "327911",
"tracking0": "64"
}

requestlink = requests.post(url = "https://secure.logmeinrescue.com/Customer/Download.aspx", data = json_payload)
stuff = requestlink.content

with open("supportlmi.exe", 'wb') as s:
    s.write(stuff)

problem is if I try to add the name to the post' body like so:

import requests

json_payload = {
"name": "Conglomo - Rocko"
"EntryID": "327911",
"tracking0": "64"
}

requestlink = requests.post(url = "https://secure.logmeinrescue.com/Customer/Download.aspx", data = json_payload)
stuff = requestlink.content

with open("supportlmi.exe", 'wb') as s:
    s.write(stuff)

Then it will error out. I figure there must be a way to pass the name into the body as you are able to do it in html using the form.

NOTE: YOU CAN USE THE HTML CODE ABOVE AND IT SHOULD WORK. I PUT IN LOGMEIN's TEST SUPPORT GROUP SO YOU CAN ACTUALLY TRY THIS IN HTML :)

EDIT: The result should be a download of Logmein's launcher. Not a status code.

I actually figured out a work around for this issue! Instead of putting the name in the body, you append the name to the url itself like so; https://secure.logmeinrescue.com/Customer/Download.aspx?name=Conglomo Rocko With doing that, I don't need to put the name in the body. The result is an exe download of Logmein's launcher! :)

CodePudding user response:

This worked for me

import requests

payload = {
"EntryID": "327911",
"tracking0": "64",
"name": "Conglomo - Rocko"
}

response = requests.post("https://secure.logmeinrescue.com/Customer/Download.aspx", json=payload)
stuff = response.content

print(stuff)
print(response.status_code)

You need to pass the payload as json to the request

  • Related