如何使用给定的json进行PHP POST请求

时间:2019-03-14 07:52:56

标签: php post

POST /身份验证/登录

内容类型:application / json

接受:application / json

{

“ dsCredentials”:{

"tenantName": "...",
"userName": "...",
"password": "...",
"applicationInfos": {
  "applicationName": "...",
  "applicationVersion": "...",
  "serverName": "...",
  "requestID": "..."
},
"mfaCode": "..."

}

}

1 个答案:

答案 0 :(得分:0)

例如,您可以使用cURL

  $data = [
    'username'      => $username,
    'email'         => $email,
    'password'      => $password
];

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($data));
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data));

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

//execute post
$result = curl_exec($ch);
echo $result;