dongyue110702
2018-01-03 05:51
浏览 123
已采纳

如何将cURL PUT语法转换为正确的PHP

I am struggling to get the Qualtrics PUT API to work using PHP.

The cURL syntax is:

    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'

I need this to work in PHP. I am trying to update the password only. I would appreciate any help as I've been trying for a while with no success.

Qualtrics doesn't provide any example PHP code but the following additional information might help:

Request Headers

Accept: */*
X-API-TOKEN: yourtokenhere
accept-encoding: gzip, deflate
content-type: application/json
content-length: 24

Request Data

{
    "password": "Password1"
}

Thanks in advance.

图片转代码服务由CSDN问答提供 功能建议

我很难让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,
“”权限“:{
”controlPanel“:{
”accountPermissions“:{
”accessApi“:{
”state“:”off“
} 
  } 
} 
} 
}''https://yourdatacenterid.qualtrics.com/API/v3/users/UR_1234567890AbCdE'
nn

我需要这个 用PHP工作。 我正在尝试更新密码。 我很感激任何帮助,因为我已经尝试了一段时间但没有成功。

Qualtrics没有提供任何示例PHP代码,但以下附加信息可能有所帮助:

请求标题

 接受:* / * 
X-API-TOKEN:yourtokenhere 
accept-encoding:gzip,deflate 
content-type:application  / json 
content-length:24 
   
 
 

请求数据

  {
“password”:“Password1  “
} 
   
 
 

提前致谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duande1985 2018-01-03 05:56
    已采纳

    Below is a sample php example based on your curl example.

    $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, "{
        \"status\": \"active\",
        \"lastName\": \"ExampleLastName\",
        \"password\": \"uwillneverguess\",
        \"firstName\": \"ExampleFirstName\",
        \"userType\": \"UT_1234567890AbCdE\",
        \"accountExpirationDate\": null,
        \"permissions\": {
            \"controlPanel\": {
                \"accountPermissions\": {
                    \"accessApi\": {
                        \"state\": \"off\"
                    }
                }
            }
        }
    }");
    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);
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题