【问题标题】:Postman and cURL is returning different outputPostman 和 cURL 返回不同的输出
【发布时间】:2019-06-17 02:23:43
【问题描述】:

这是我在邮递员中运行的网址:-http://213.252.244.214/create-signature.php。它有两个参数stringkey。它将返回您输入的inputRJAGDhoz8yDJ7GwVLberI/NMYy2zMTTeR9YzXj7QhCM= 的输出,但如果我从 curl 运行它,那么它将返回D9UmS6r/qg0QI/0eIakifqrM3Nd1g6B3W7RCsiyO7sc=。输出为 JSON 格式。以下是 cURL 代码:-

public function create_signature($input, $key) {
        $ch = curl_init();    
        curl_setopt($ch, CURLOPT_URL,'http://213.252.244.214/create-signature.php');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "string=$input&key=$key");                   
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $output = curl_exec($ch);
        $json = json_decode($output);
        $signature = $json->output; echo $signature; echo '<br>';
        curl_close($ch);
        return $signature;
    }

示例字符串是:-2019-01-23 14:00:594lzUTYHw01dW5EmPan01M07hEiWUaEmdKl3kzpUUqak=Ha2wZwz46l7vSboxVNx3/DAUYsInjjKtAbDSnPsdDnA=igK7XzaTBrusPc3q5OEOQg==igK7XzaTBrusPc3q5OEOQg==1.0.110671523012111548248459fR9b/McBCzk=Deposit Fund698EURLuisTurinTurinVenis13212TF990303274103325689667lg@gmail.comLuisTurinTurinVenis13212TF990303274103325689667lg@gmail.comLuisTurinTurinVenis13212TF990303274103325689667lg@gmail.comclient_deposithttp://localhost/feature/CD-716/gateways/certus_finance/paymenthttp://localhost/feature/CD-716/gateways/certus_finance/paymenthttp://localhost/feature/CD-716/gateways/certus_finance/payment

示例密钥是:- 85e1d7a5e2d22e46

谁能告诉我为什么不一样??任何帮助将不胜感激。

【问题讨论】:

    标签: php json codeigniter curl postman


    【解决方案1】:

    您的 $input$key 值没有被编码。来自curl_setopt()manual page...

    此参数可以作为urlencoded 字符串 ...或作为字段名称作为键和字段数据作为值的数组传递

    邮递员默认这样做。

    为了避免手动编码字符串,只需使用数组方法

    curl_setopt($ch, CURLOPT_POSTFIELDS, [
        'input' => $input,
        'key'   => $key
    ]);
    

    请注意此警告...

    注意:
    将数组传递给 CURLOPT_POSTFIELDS 会将数据编码为 multipart/form-data,而传递 URL 编码的字符串会将数据编码为 application/x-www -form-urlencoded.

    如果需要,为确保application/x-www-form-urlencoded,您可以使用http_build_query() 构建编码字符串,例如

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
        'input' => $input,
        'key'   => $key
    ]));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多