【问题标题】:cpprestsdk http credentials setting gets 401 errorcpprestsdk http 凭据设置出现 401 错误
【发布时间】:2020-05-20 21:30:18
【问题描述】:
//Basic Authorization Setting
http_client_config config;
credentials creds(L"name", L"password");
config.set_credentials(creds);
http_client client(U("http://severip/"), config);

// create header
http_request req(methods::GET);

//// Add base64 result to header
req.headers().add(L"Authorization", L"Basic bmFtZTpwYXNzd29yZA");
req.set_request_uri(L"/_cat/master");
pplx::task<http_response> responses = client.request(req);
pplx::task<web::json::value> jvalue = responses.get().extract_json();
web::json::value v = jvalue.get();
utility::string_t jsonval = v.serialize();
wcout << jsonval << endl;

//with base64 encoding.
//bmFtZTpwYXNzd29yZA = name:password

我正在尝试通过 cpprestsdk aka casablanca 设置凭据。

我收到了 401 错误,无法验证用户,这意味着密码错误。

任何建议将不胜感激。

【问题讨论】:

    标签: http elasticsearch credentials casablanca cpprest-sdk


    【解决方案1】:

    尝试使用 curl 命令快速验证用户/密码。

    
    curl -X PUT --basic  -u {user}:{password} http://severip/
    
    

    【讨论】:

    • 感谢 cmets。我知道用户/密码信息。问题是,我的用户和密码是正确的,并且 curl 命令运行良好,但它通过 cpprest-sdk 吐出 401 错误。我认为这是来自代码问题。有什么想法吗?
    • curl -H 'Authorization:Basic bmFtZTpwYXNzd29yZA' -H 'Content-Type: application/json' 验证base 64是否正确。
    • 我有 curl:(6)无法解析主机:bmFtZTpwYXNzd29yZA curl:(6)无法解析主机:应用程序这是否意味着我的 base64 字符串不正确?
    • curl http://${severip}/${port}/_cat/master -H 'Authorization:Basic bmFtZTpwYXNzd29yZA' -H 'Content-Type: application/json'
    • {"error":{"root_cause":[{"type":"security_exception","re​​ason":"缺少 REST 请求的身份验证凭据 [/_cat/master]","header" :{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","re​​ason":"缺少 REST 请求的身份验证凭据[/_cat/master]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401}curl: ( 6)无法解析主机:bmFtZTpwYXNzd29yZA' curl:(6)无法解析主机:应用程序
    猜你喜欢
    • 1970-01-01
    • 2019-03-24
    • 2013-09-22
    • 1970-01-01
    • 2017-09-16
    • 2016-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多