2017-02-26 7 views
0

私はHTTPポストリクエストを送信して応答できるプログラムを作りたいと思います。PythonでHTTPポストを送信

POST https: //example.com/index.php?s=&&app=box&module=ajax&section=coreAjax&secure_key=&type=submit&lastid=87311&global=1 HTTP/1.1 
Host: example.com 
Connection: keep-alive 
Content-Length: 10 
Accept: text/javascript, text/html, application/xml, text/xml, */* 
X-Prototype-Version: 1.7.2 
Origin: https://example.com 
X-Requested-With: XMLHttpRequest 
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 
Content-type: application/x-www-form-urlencoded; charset=UTF-8 
Referer: https://x.com/ 
Accept-Encoding: gzip, deflate, br 
Accept-Language: en-US,en;q=0.8 
Cookie: cookieconsent_status=dismiss; 

そしてリクエストボディを入力します。:

だから、私はこの記事を送りたい

message=     # Which I will make: "message= %s" % (messagex)) 

をしかし、私はそれらを送信する方法がわからないと見つけるように見えるcan'tオンラインでも、誰かが助けてくれますか?

+1

http://requests.readthedocs.io/ja/master/をご覧ください。またはhttplibライブラリですか? – ValLeNain

+0

@ValLeNainええ、でも、私はPythonにはまったく新しいので、これをどうやって行うのかは分かっていません。/ – Hubgum

+0

カスタムヘッダーと複雑なPOSTリクエスト(http://requests.readthedocs.io/en)/master/user/quickstart /#custom-headers)、これはあなたが必要とするものであり、非常に簡単です。 StackOverflowで投稿する前に何か試してみることを忘れないでください;) – ValLeNain

答えて

0

主な部品は以下のとおりです。助け

import requests # you have to install this library, with pip for example 

# define your custom headers (as many as you want) 

headers = { 
    'X-Prototype-Version': '1.7.2' 
} 

# define your URL params (!= of the body of the POST request) 

params = { 
    'your_first_param': 'its_value', 
    'your_second_param': 'its_value' 
} 

# define the body of the POST request 

data = { 
    'message' : 'your message' 
} 

# send the POST request 

response = requests.post('https://example.com/index.php', params=params, data=data, headers=headers) 

# here is the response 

print response.text 

希望。

関連する問題