【问题标题】:Unable to integrate Azure ML API with PHP无法将 Azure ML API 与 PHP 集成
【发布时间】:2016-05-30 06:51:11
【问题描述】:

我尝试将 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);

我遵循了几个例子,仍然无法破解它。请告诉我解决方案。

【问题讨论】:

    标签: php azure curl machine-learning azure-machine-learning-studio


    【解决方案1】:

    根据错误信息,我认为该问题是由于请求 ML REST API 而没有正确的 json body 引起的。

    我建议您可以参考文章"Getting started with the Text Analytics APIs to detect sentiment, key phrases, topics and language",将您的输入行正确格式化为JSON格式作为请求正文,然后重试。

    希望对你有帮助。

    如果您可以更新您的问题以指定您使用的 ML REST API,我认为这对找出问题非常有帮助。

    期待您的更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-17
      • 1970-01-01
      • 2011-11-24
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多