gpt4 book ai didi

https - CppRestSDK https 请求不工作

转载 作者:行者123 更新时间:2023-12-01 14:30:38 24 4
gpt4 key购买 nike

这将返回错误代码 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com