休息后请求与chilkat lib

时间:2019-06-25 13:18:42

标签: c++ rest post access-token chilkat

当尝试使用chilkat库在c ++中实现时,带有邮递员接口的工作邮递请求不起作用,邮递员得到响应200,程序得到401(未授权)。 我正在用chilkat的示例进行休息后请求。

无论您在哪里看到用户名和密码,都将填写有效值。

休息休息;

//  Make the initial connection (without sending a request yet).
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = rest.Connect("https://dev-182721.oktapreview.com",port,bTls,bAutoReconnect);
if (success != true) {
    std::cout << rest.lastErrorText() << "\r\n";
    return;
}
rest.put_Authorization("username:password");
rest.authorization();

rest.AddHeader("Content-Type","application/x-www-form-urlencoded");

//  Provide query params.
rest.AddQueryParam("grant_type","password");
rest.AddQueryParam("redirect_uri","http://localhost");
rest.AddQueryParam("username","username");
rest.AddQueryParam("password","password");
rest.AddQueryParam("scope","openid");


const char *responseStr= 
rest.fullRequestFormUrlEncoded("POST","/oauth2/default/v1/token");

if (rest.get_LastMethodSuccess() != true) {
    std::cout << rest.lastErrorText() << "\r\n";
    return;
}

//  When successful, the response status code will equal 200.

任何人都可以帮助我找出丢失的内容

1 个答案:

答案 0 :(得分:0)

Okta访问令牌示例可在此处获得:https://www.example-code.com/cpp/okta_oauth_oidc.asp