https - CppRestSDK https 请求不工作

标签 https speech-to-text bing bing-api microsoft-cognitive

这将返回错误代码 401500。有人可以帮助我哪里出错了吗?

http_client client(L"https://oxford-speech.cloudapp.net/token/issueToken/");    
uri_builder query;
query.append_query(L"grant_type", L"client_credentials");       
query.append_query(L"client_id", L"test-app");
query.append_query(L"client_secret", L"<client secret goes here>");
query.append_query(L"scope", L"https://speech.platform.bing.com");
query.append_query(L"content_type", L"application/x-www-form-urlencoded");

http_request msg(methods::POST);
msg.headers().set_content_type(L"application/x-www-form-urlencoded");
msg.set_request_uri(query.to_string());

std::wstring str = msg.to_string();
return client.request(msg);

最佳答案

谢谢大家。我将代码更改为以下,我得到了 token !

pplx::task<void> getAccessToken()
{
istream bodyStream;
http_client client(L"https://api.cognitive.microsoft.com/sts/v1.0/issueToken");
http_request req(methods::POST);
req.headers().add(L"Ocp-Apim-Subscription-Key", L"YOUR_KEY");

return client.request(req)

.then([](http_response response)
{
    if (response.status_code() != status_codes::OK)
    {
        return pplx::task_from_result();
    }
    istream bodyStream = response.body();
    container_buffer<std::string> inStringBuffer;       
    return bodyStream.read_line(inStringBuffer)

.then([inStringBuffer](size_t bytesRead)
{
    const std::string &text = inStringBuffer.collection();
    std::cout << text;
});

});
};

关于https - CppRestSDK https 请求不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40917338/

相关文章:

java - 在 Android 上使用自定义异常词匹配进行语音转文本

nlp - 在哪里可以找到搜索引擎查询的语料库?

seo - osclass如何获取一个item的城市区域信息

python - 获取 Bing 的表单名称

apache - 如何在本地轻松地通过 HTTPS 提供静态文件

android - 从自己的声音文件语音到文本

audio - 如何将语音转换为文本?

php - Paypal IPN 安全性已验证

apache - HTTPS 网站的 ELB 和 Apache 配置

ssl - Cloudflare SSL 证书引发安全问题