1.发送POST请求,携带json数据

  1. public static function doPost2($url, array $params)
  2. {
  3. $options = array(
  4. 'http' => array(
  5. 'method' => 'POST',
  6. 'content' => json_encode($params),
  7. 'header' => "Content-Type: application/json\r\n" .
  8. "Accept: application/json\r\n"
  9. )
  10. );
  11. $context = stream_context_create($options);
  12. $result = file_get_contents($url, false, $context);
  13. $response = json_decode($result, true);
  14. return $response;
  15. }