【发布时间】:2019-07-05 00:53:25
【问题描述】:
当尝试使用 chilkat 库在 c++ 中实现时,使用 postman 接口的工作发布请求不起作用,使用 postman 我得到响应 200,使用程序我得到 401(未经授权)。 我正在使用 chilkat 的示例来请求休息。
无论您在哪里看到用户名和密码,都会填写有效值。
ckrest休息;
// 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.
谁能帮我弄清楚缺少什么
【问题讨论】:
标签: c++ rest post access-token chilkat