觀察 GET / POST 的差別

透過 postman 網站的測試觀察 GET 與 POST 之間的差別


In [1]:
import requests
from pprint import pformat

GET request

  • 觀察回傳的內容
  • 觀察 URL

In [2]:
get_url = 'https://postman-echo.com/get'
query = {
    'name': 'afun',
    'msg': 'A Foolish Consistency is the Hobgoblin of Little Minds'
}

get_resp = requests.get(get_url, params=query)

In [3]:
print('response text', pformat(get_resp.text))
print('='*87)
print('original URL -', get_url)
print('GET URL -', get_resp.url)


response text ('{"args":{"name":"afun","msg":"A Foolish Consistency is the Hobgoblin of '
 'Little '
 'Minds"},"headers":{"host":"postman-echo.com","accept":"*/*","accept-encoding":"gzip, '
 'deflate","user-agent":"python-requests/2.19.1","x-forwarded-port":"443","x-forwarded-proto":"https"},"url":"https://postman-echo.com/get?name=afun&msg=A+Foolish+Consistency+is+the+Hobgoblin+of+Little+Minds"}')
=======================================================================================
original URL - https://postman-echo.com/get
GET URL - https://postman-echo.com/get?name=afun&msg=A+Foolish+Consistency+is+the+Hobgoblin+of+Little+Minds

POST request

  • 觀察回傳的內容
  • 觀察 URL

In [4]:
post_url = 'https://postman-echo.com/post'
payload = 'A Foolish Consistency is the Hobgoblin of Little Minds'

post_resp = requests.post(post_url, data=payload)

In [5]:
print('response text', pformat(post_resp.text))
print('='*87)
print('original URL -', post_url)
print('GET URL -', post_resp.url)


response text ('{"args":{},"data":{},"files":{},"form":{},"headers":{"host":"postman-echo.com","content-length":"54","accept":"*/*","accept-encoding":"gzip, '
 'deflate","user-agent":"python-requests/2.19.1","x-forwarded-port":"443","x-forwarded-proto":"https"},"json":null,"url":"https://postman-echo.com/post"}')
=======================================================================================
original URL - https://postman-echo.com/post
GET URL - https://postman-echo.com/post

In [6]:
query = {
    'name': 'afun',
    'msg': 'A Foolish Consistency is the Hobgoblin of Little Minds'
}
post_form_data_resp = requests.post(post_url, data=query)

In [7]:
print('response text', pformat(post_form_data_resp.text))
print('='*87)
print('original URL -', post_url)
print('GET URL -', post_form_data_resp.url)


response text ('{"args":{},"data":"","files":{},"form":{"name":"afun","msg":"A Foolish '
 'Consistency is the Hobgoblin of Little '
 'Minds"},"headers":{"host":"postman-echo.com","content-length":"68","accept":"*/*","accept-encoding":"gzip, '
 'deflate","content-type":"application/x-www-form-urlencoded","user-agent":"python-requests/2.19.1","x-forwarded-port":"443","x-forwarded-proto":"https"},"json":{"name":"afun","msg":"A '
 'Foolish Consistency is the Hobgoblin of Little '
 'Minds"},"url":"https://postman-echo.com/post"}')
=======================================================================================
original URL - https://postman-echo.com/post
GET URL - https://postman-echo.com/post