Skip to content

Instantly share code, notes, and snippets.

@blanklin030
Last active September 19, 2018 09:34
Show Gist options
  • Save blanklin030/5535ee18a6c9fbdc71302fe994ebe546 to your computer and use it in GitHub Desktop.
Save blanklin030/5535ee18a6c9fbdc71302fe994ebe546 to your computer and use it in GitHub Desktop.
http请求参数之:query string parameters 与 form data 与 request payload的区别

http请求报头

Query String Parameters

// General
Request URL: http://foo.com?x=1&y=2
Request Method: GET

// Query String Parameters
x=1&y=2

当使用get方式请求http时,默认为Query String Parameters

获取方式:

$params = $_GET['params'];

Form Data

// General
Request URL: http://foo.com
Request Method: POST

// Request Headers
content-type: application/x-www-form-urlencoded; charset=UTF-8

// Form Data
x=1&y=2

当使用post方式请求时默认是为form data

获取方式:

$params = $_POST['params'];

Request Payload

// General
Request URL: http://foo.com
Request Method: POST

// Request Headers
content-type: application/json; charset=UTF-8

// Request Payload
x=1&y=2

当使用post方式请求时,如果设置了content-type是application/json时,返回Request Payload

获取方式:

$params = json_decode(file_get_contents('php://input'),true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment