[英]Why does my POST request time out in PHP using cURL, but not in Postman?
I have an auth.php file that should make a request to an API with some headers, data and stuff.我有一个 auth.php 文件,它应该向带有一些标题、数据和内容的 API 发出请求。
I tried Postman , and gave me a response almost immediately.我尝试了Postman ,几乎立即就给了我答复。
I copied the code (PHP > cURL) and tried it, and it would be waiting for MYPRIVATESITE.com
for 30 seconds (I set the timeout to that), and then just cURL ERROR: TIMED OUT
(or something like that).我复制了代码 (PHP > cURL) 并尝试了它,它会
waiting for MYPRIVATESITE.com
30 秒(我将超时设置为那个),然后只是cURL ERROR: TIMED OUT
超时(或类似的东西)。
What did I do wrong?我做错了什么? It works with eg postman, so why not my website?
它适用于例如邮递员,那么为什么我的网站不适用?
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://discordapp.com/api/v6/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "client_id=PRIVATEID&client_secret=PRIVATEKEY&grant_type=authorization_code&code=$code&redirect_uri=https%3A%2F%2Fkanebot.epizy.com%2Fauth.php&scope=identify%20guilds&undefined=",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
"cache-control: no-cache"
)
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Note: The PRIVATEKEY
and PRIVATEID
are there, I just remove them because I don't want anyone else to steal it.注意:
PRIVATEKEY
和PRIVATEID
在那里,我只是删除它们,因为我不希望其他人窃取它。 It's defined, and it worked (read up).它已定义,并且有效(阅读)。 The
$code
is also defined.还定义了
$code
。
You are missing the &
operator in your POSTFIELDS
between the client_secret
and the grant_type
这是因为丢失了
&
您的运营商POSTFIELDS
之间client_secret
和grant_type
try to add the &
and see if its working after (it will sure solve one of the problems you have)尝试添加
&
并查看它之后是否有效(它肯定会解决您遇到的问题之一)
client_id=PRIVATEID&client_secret=PRIVATEKEYgrant_type=authorization_code&code=$code&redirect_uri=https%3A%2F%2Fkanebot.epizy.com%2Fauth.php&scope=identify%20guilds&undefined=
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.