Php IBM Watson自然语言理解仅获取英语短语
IBM Watson Natural Language Understanding的小型应用程序在通过POST(php)接收时仅获取英语短语。 当我发法语、西班牙语或葡萄牙语邮件时,它们都不起作用 我的代码: 包括_once('JSON.php'); $json=newservices_json() //获取参数 $protocol=utf8_解码(($_GET['protocol'])?$_GET['protocol']:$_POST['protocol']); $report=utf8_解码(($_GET['report'])?$_GET['report']:$_POST['report']); $class=utf8_解码($_GET['classified'])?$_GET['classified']:$_POST['classified']) //打电话给沃森Php IBM Watson自然语言理解仅获取英语短语,php,curl,post,get,watson,Php,Curl,Post,Get,Watson,IBM Watson Natural Language Understanding的小型应用程序在通过POST(php)接收时仅获取英语短语。 当我发法语、西班牙语或葡萄牙语邮件时,它们都不起作用 我的代码: 包括_once('JSON.php'); $json=newservices_json() //获取参数 $protocol=utf8_解码(($_GET['protocol'])?$_GET['protocol']:$_POST['protocol']); $report=utf8_解码
$report = strtoupper($report);
$username = 'xxxxxxx';
$password = 'XXXXX';
$url = 'https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27&text=Helloethics&features=entities,sentiment,keywords';
// Set post arguments for call
$post_args = array(
'text' => $report
);
// Set header arguments for call
$header_args = array(
'Content-Type: text/plain',
'Accept: application/json'
);
// Set options for REST call via curl
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_USERPWD, "xxxxxxxx:XXXXXXX");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header_args);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_args);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Actual REST call via curl and cleanup (closing) of curl call
$result = curl_exec($curl);
print_r($result);
curl_close($curl);
POST/GET仅在Prasher为英语时有效,但其他语言返回:
只有当Prasher为英语,但其他语言返回时,POST才起作用:
{“语言”:“pt”,“实体”:[],“警告”:[“关键字:内部服务器错误”,“情绪:内部服务器错误”]}
但是,当我使用一个局部变量时,OK,起作用了。请帮帮我!谢谢大家! 解决了
一致
$report=utf8_解码(($_GET['report'])?$_GET['report']:$_POST['report'])
只需删除utf8_解码
工作 解决了
一致
$report=utf8_解码(($_GET['report'])?$_GET['report']:$_POST['report'])
只需删除utf8_解码
工作