如何将 cURL PUT 语法转换为更正 PHP
How to convert cURL PUT syntax to correct PHP
我正在努力让 Qualtrics PUT API 使用 PHP 工作。
cURL 语法为:
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 代码,但以下附加信息可能会有所帮助:
请求Headers
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);
我正在努力让 Qualtrics PUT API 使用 PHP 工作。
cURL 语法为:
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 代码,但以下附加信息可能会有所帮助:
请求Headers
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);