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.

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 如何能达到用ping0.cc检测成这样?如图
  • ¥15 关于#DMA固件#的问题,请各位专家解答!
  • ¥15 matlab生成的x1图不趋于稳定,之后的图像是稳定的水平线
  • ¥15 请问华为OD岗位的内部职业发展通道都有哪些,以及各个级别晋升的要求
  • ¥20 微信小程序 canvas 问题
  • ¥15 系统 24h2 专业工作站版,浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式
  • ¥15 MATLAB的动态模态分解出现错误,以CFX非定常模拟结果为快照
  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?