none
必应拼写检查API 响应返回异常 RRS feed

  • 问题

  • 代码:

    <?php

    $subscriptionKey = '5aba2e2ebfab4b4cb4e929814a3d15a';

    $host = "https://api.cognitive.microsoft.com";
    $path = "/bing/v7.0/Suggestions";

    $mkt = "en-US";
    $query = "hollo";

    function get_suggestions ($host, $path, $key, $mkt, $query) {

    $params = '?mkt=' . $mkt . '&q=' . $query;

    $headers = "Content-type: text/json\r\n" .
    "Ocp-Apim-Subscription-Key: $key\r\n";

    $options = array (
    'http' => array (
    'header' => $headers,
    'method' => 'GET'
    )
    );
    $context = stream_context_create ($options);
    $result = file_get_contents ($host . $path . $params, false, $context);
    return $result;
    }

    $result = get_suggestions ($host, $path, $subscriptionKey, $mkt, $query);

    echo json_encode (json_decode ($result), JSON_PRETTY_PRINT);
    ?>

    返回数据:

    { "_type": "SpellCheck", "flaggedTokens": [] }

    2019年11月7日 6:55