如何将cURL-PUT语法转换为正确的PHP
我正在努力使用PHP使Qualtrics PUT API正常工作 cURL语法是:如何将cURL-PUT语法转换为正确的PHP,php,api,curl,put,Php,Api,Curl,Put,我正在努力使用PHP使Qualtrics PUT API正常工作 cURL语法是: curl -X PUT -H 'X-API-TOKEN: yourtokenhere' -H 'Content-Type: application/json' -d '{ "status": "active", "lastName": "ExampleLastName", "password": "uwillneverguess", "firstName": "Examp
curl -X PUT -H 'X-API-TOKEN: yourtokenhere' -H 'Content-Type: application/json' -d '{
"status": "active",
"lastName": "ExampleLastName",
"password": "uwillneverguess",
"firstName": "ExampleFirstName",
"userType": "UT_1234567890AbCdE",
"accountExpirationDate": null,
"permissions": {
"controlPanel": {
"accountPermissions": {
"accessApi": {
"state": "off"
}
}
}
}
}' 'https://yourdatacenterid.qualtrics.com/API/v3/users/UR_1234567890AbCdE'
我需要这个在PHP中工作。我只想更新密码。我将感谢任何帮助,因为我已经尝试了一段时间,但没有成功
Qualtrics没有提供任何PHP代码示例,但以下附加信息可能会有所帮助:
请求头
Accept: */*
X-API-TOKEN: yourtokenhere
accept-encoding: gzip, deflate
content-type: application/json
content-length: 24
请求数据
{
"password": "Password1"
}
提前感谢。下面是一个基于curl示例的php示例
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://yourdatacenterid.qualtrics.com/API/v3/users/UR_1234567890AbCdE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"status\": \"active\",\n \"lastName\": \"ExampleLastName\",\n \"password\": \"uwillneverguess\",\n \"firstName\": \"ExampleFirstName\",\n \"userType\": \"UT_1234567890AbCdE\",\n \"accountExpirationDate\": null,\n \"permissions\": {\n \"controlPanel\": {\n \"accountPermissions\": {\n \"accessApi\": {\n \"state\": \"off\"\n }\n }\n }\n }\n}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "X-Api-Token: yourtokenhere";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
感谢Abhinav Verma的回答:
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, "https://yourdatacenterid.qualtrics.com/API/v3/users/UR_1234567890AbCdE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"status\": \"active\",\n \"lastName\": \"ExampleLastName\",\n \"password\": \"uwillneverguess\",\n \"firstName\": \"ExampleFirstName\",\n \"userType\": \"UT_1234567890AbCdE\",\n \"accountExpirationDate\": null,\n \"permissions\": {\n \"controlPanel\": {\n \"accountPermissions\": {\n \"accessApi\": {\n \"state\": \"off\"\n }\n }\n }\n }\n}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "X-Api-Token: yourtokenhere";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
嗨,阿比纳夫,谢谢你的快速回复,我很感激。我只是用实际的令牌和UR_xxx尝试了一下,我得到了以下错误:错误:SSL证书问题:无法获取本地颁发者证书D多行忽略SSL警告和错误:curl_setopt$ch,CURLOPT_SSL_VERIFYHOST,0;除此之外,还有一个很好的PHP库,主要用于API调用:试试这些curl_setopt$ch,CURLOPT_FOLLOWLOCATION,TRUE;curl_setopt$ch,CURLOPT_SSL_VERIFYPEER,false;非常感谢阿比纳夫,非常感谢你的帮助!