如何用php模拟json请求
只需设置header头
```
$url ="http://www.test.com/articles/_search?size=10&from=$from";
$json_data = json_encode ( $params );
$json_data = "{'name':'test'}";
$result = curl ( $url, $json_data, "GET" );
```
```
function curl($url, $postDate = "", $method = "PUT") {
//echo "url=>".$url."
";
$ci = curl_init ();
$headers = array(
"Content-type: application/json;charset='utf-8'",
"Accept: application/json",
"Cache-Control: no-cache",
"Pragma: no-cache",
);
curl_setopt ( $ci, CURLOPT_URL, $url );
curl_setopt ( $ci, CURLOPT_PORT, 10026 );
curl_setopt ( $ci, CURLOPT_TIMEOUT, 200 );
curl_setopt ( $ci, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ci, CURLOPT_FORBID_REUSE, 0 );
curl_setopt ( $ci, CURLOPT_CUSTOMREQUEST, $method );
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
if ($postDate) {
curl_setopt ( $ci, CURLOPT_POSTFIELDS, $postDate );
}
$response = curl_exec ( $ci );
return $response;
}
```