gpt4 book ai didi

php - 如何使用 curl 对 token 进行编码

转载 作者:搜寻专家 更新时间:2023-10-31 21:36:08 25 4
gpt4 key购买 nike

第 1 步

我正在使用 CURL 发送一个 xml 请求,它向我返回“TOKEN”。请在此处找到以下代码:

<root><request><type>mykey</type><username>myusername</username><password>mypassword</password></request></root>

$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $curl_url);// passing API URL here
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $xml_strign); // passing xml as a string
$result = curl_exec ($curl_handle);

在上面的代码中,执行正常并返回 Token 作为结果。

第 2 步

在第二步中,我必须发送上面的 token 才能得到我的结果但没有得到结果。请找到下面的代码:

$xml = "<root>
<request>
<type>myparam</type>
<token>lGcvdOnetuxK0paE+AIxE93GB85DURIpOeoBw8quqOs=</token>
</request>
</root>";

curl_setopt($curl_handle, CURLOPT_URL, $curl_url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $xml);
$result = curl_exec ($curl_handle);
curl_close ($curl_handle);
print_r($result);

我猜可能这个 token 包含特殊章程,所以我没有得到结果。我在浏览器中看到控制台 url 响应状态为 200 ok。

非常感谢您的帮助。

最佳答案

我认为您的帖子数据有问题。您应该在此处阅读有关 CURLOPT_POSTFIELDS 的详细信息:

http://php.net/manual/fr/function.curl-setopt.php

所以你的 xml 变量可能应该这样定义:

$xml = array("token" => "lGcvdOnetuxK0paE+AIxE93GB85DURIpOeoBw8quqOs");

至少应该是一个数组。

关于php - 如何使用 curl 对 token 进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19151785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com