使用场景
发现如下错误需要将CURL的SSL由NSS改为OpenSSL的
cURL error 35: A PKCS #11 module returned CKR_DEVICE_ERROR, indicating that a problem has occurred with the token or slot. (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
上述错误原因有可能是使用pcntl_fork子进程未被回收导致
使用file_get_contents()
注意: 添加header头需要以 \r\n
换行
$url = 'http://test.aa/api';
$response = ['timestamp'=> $time,'model_id'=> $modelId,'city_ids'=> $cityIds,
];
$key = "asdfasdfasdlfjlksdjfk";
$postdata = http_build_query($response);
$options = ['http' =>['method' => 'POST','header' => "Content-type:application/x-www-form-urlencoded\r\n" ."key: $key",'content' => $postdata,'timeout' => 15*60]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$body = json_decode($result, true);