云盾身份认证二要素接口提示参数非法(curl用get方法传中文参数乱码)

文章讲述了在使用PHP的curl库调用接口时遇到的两个问题:返回值包含头部信息影响JSON解析,以及中文参数导致的非法参数错误。通过调整curl选项,设置Content-Type头,以及对中文参数使用URLencode处理,成功解决了这两个问题。接口参数的正确编码方式是百分号和16进制数字的组合,即URLencode编码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 接口文档给的示例代码如下图:

<?php
    $host = "http://id2meta.market.alicloudapi.com";
    $path = "/id2meta";
    $method = "GET";
    $appcode = "你自己的AppCode";
    $headers = array();
    array_push($headers, "Authorization:APPCODE " . $appcode);
    $querys = "identifyNum=identifyNum&identifyNumMd5=identifyNumMd5&userName=userName&userNameMd5=userNameMd5";
    $bodys = "";
    $url = $host . $path . "?" . $querys;

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, true);
    if (1 == strpos("$".$host, "https://"))
    {
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    }
    var_dump(curl_exec($cu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值