使用D8上面的代码发布表单,我收到以下错误:
cURL error 77: error setting certificate verify locations: CAfile: C:\Program Files (x86)\DevDesktop\common\cert\cacert.pem CApath: none (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
我的问题是如何修改此代码以不验证或如何设置证书以便我不会收到此错误。感谢
$url = "https://jsonplaceholder.typicode.com/posts";
$client = \Drupal::httpClient();
$post_data = array('color' => 'red');
$response = $client->request('POST', $url, [
'headers' => ['Content-Type' => 'application/json'],
'body' => rawData($post_data),
]);
$body = $response->getBody()->getContents();
$status = $response->getStatusCode();
答案 0 :(得分:0)
这对我有用,我添加了verify => false:
$url="jsonplaceholder.typicode.com/posts
$client = \Drupal::httpClient();
$post_data = $form_state->cleanValues()->getValues();
$response = $client->request('POST', $url,
[ 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
'form_params' => $post_data,
'verify'=>false, ]);
$body = $response->getBody()->getContents();
$status = $response->getStatusCode();
dsm($body);
dsm($status);