3 回答

TA貢獻1982條經驗 獲得超2個贊
這應該工作正常!我收到訪問被拒絕錯誤,所以,這意味著代碼工作正常。
注意 您可能需要更改為http_build_query($fields)$fields
$url = "https://mpop-sit.hepsiburada.com/api/authenticate/";
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$fields = array(
"username" => "xyz_dev",
"password" => "XYZ_dev123!"
);
$header = array(
'Content-Type: application/json',
'Authorization' => 'Bearer ' . $token,
);
//open curl connection
$ch = curl_init();
//set the url, fields, vars
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); // SSL false if not required
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); //False if not required
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute fields
$result = curl_exec($ch);
//return result echo $result; if you need
echo curl_error($ch);
//close curl connection
curl_close($ch);
請讓我知道它是否有效!
更新 :如果你想使用ssl,它可以讓你免受黑客攻擊。
按照此答案中的步驟激活 ssl : https://stackoverflow.com/a/59919558/12232340

TA貢獻1843條經驗 獲得超7個贊
2 slashes here, so it does not work:
$url = 'https://mpop-sit.hepsiburada.com//api/authenticate';

TA貢獻1111條經驗 獲得超0個贊
Do you need the authentication header for this endpoint?
Because what the sample request wants you to send the parameters in the request body like this:
$post = [
'username' => 'xyz_dev',
'password' => 'XYZ_dev123!',
'authenticationType' => 'INTEGRATOR'
];
$url = 'https://mpop-sit.hepsiburada.com//api/authenticate';
$ch = curl_init($url);
$header = array('Content-Type: application/json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
$return=json_decode($result,true);
print_r($return);
So no need fot the header, it would also be created differently.Authentication: Bearer ...
- 3 回答
- 0 關注
- 181 瀏覽
添加回答
舉報