简体   繁体   中英

How to send a payload with python requests

So I understand the concept of sending payloads with requests, but I am struggling to understand how to know what to send.

for example, payload = {'key1': 'value1', 'key2': 'value2'} is the payload, but how do I find what key1 is? Is it the element ID? I have worked closely to selenium and I am looking at requests at a faster alternative.

Thanks for your help, Jake.

Requests is a library which allows you to fetch URL's using GET, POST, PUT, etc requests. On some of those you can add a payload, or extra data which the server uses to do something.

So the payload is handled by the server, but you have to supply them which you do by defining that dictionary. This is all dependent on what the server expects to receive. I am assuming you read the following explanation:

Source

You often want to send some sort of data in the URL's query string. If you were constructing the URL by hand, this data would be given as key/value pairs in the URL after a question mark, eg httpbin.org/get?key=val. Requests allows you to provide these arguments as a dictionary of strings, using the params keyword argument. As an example, if you wanted to pass key1=value1 and key2=value2 to httpbin.org/get, you would use the following code:

 >>> payload = {'key1': 'value1', 'key2': 'value2'} >>> r = requests.get('https://httpbin.org/get', params=payload) 

The payload here is a variable which defines the parameters of a request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM