无法将Azure ML API与PHP集成



我尝试将Azure ML API与PHP集成,但不幸的是,响应中出现错误。

更新:我使用了通过json响应发送的请求响应API

以下是在执行PHP脚本时获得的响应:

array(1) { ["error"]=> array(3) { ["code"]=> string(11) "BadArgument" 
["message"]=> string(26) "Invalid argument provided." ["details"]=> array(1)
{[0]=> array(2) { ["code"]=> string(18) "RequestBodyInvalid" ["message"]=>
string(68) "No request body provided or error in deserializing the request
body." } } } }

PHP脚本:

$url = 'URL';
$api_key = 'API';
$data = array(
'Inputs'=> array(
'My Experiment Name'=> array(
"ColumnNames" => [['Column1'],
['Column2'],
['Column3'],
['Column4'],
['Column5'],
['Column6'],
['Column7']],
"Values" => [ ['Value1'],
['Value2'],
['Value3'],
['Value4'],
['Value5'],
['Value6'],
['Value7']]
),
),
'GlobalParameters' => new StdClass(),
);
$body = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$api_key, 'Accept: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response  = json_decode(curl_exec($ch), true);
//echo 'Curl error: ' . curl_error($ch);
curl_close($ch);
var_dump ($response);

我已经举了几个例子,但仍然无法破解。请让我知道这个问题的解决方案。

根据错误信息,我认为问题是由于请求了没有正确json主体的MLRESTneneneba API而引起的。

我建议您可以参考文章"开始使用文本分析API来检测情绪、关键短语、主题和语言",以正确地将JSON中的输入行格式化为请求体,然后重试。

希望能有所帮助。

如果您可以更新您的问题以指定您使用的MLRESTneneneba API,我认为这对解决问题非常有帮助。

期待您的更新。

最新更新