php curl 发送post请求
php curl 发送post请求<?php$url = "https://gateway.watsonplatform.net/language-translation/api/v2/translate";echo $url;$post_data = array("username" => "5ce64022
php curl 发送post请求
<?php
$url = "https://gateway.watsonplatform.net/language-translation/api/v2/translate";
echo $url;
$post_data = array("username" => "5ce64022d2e8c1","password" => "51ko","source" => "en", "target" => "zh-cn", "text" => "Hello World");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
//打印获得的数据
print_r($output);2023-05-02 更新
注意:访问 https 开头的地址,可能会因为网站的证书不被识别,证书过期等问题导致错误,添加以下代码可以解决:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/lang/2022-10-31/1559.html
2022-10-31
2
0


