0

我正在 MFC 框架中构建 Git 客户端,并且我正在使用 casablanca 库来与 github 服务器建立连接并使用它的 API。在 Github 教程中,一个示例显示了如何向 github 服务器发送请求,并附上用户名和密码以进行身份​​验证:
https ://developer.github.com/v3/#authentication

curl -i https://api.github.com -u valid_username:valid_password  

现在,我已经尝试并尝试使用 Microsoft 的 casablanca 达到相同的效果,但我根本无法获得正确的语法:

http_client client(U("https://api.github.com/users/myuser"));
uri_builder builder(U("- u myuser:mypass"));
pplx::task<http_response> requestTask = client.request(methods::GET, builder.to_string());  

调用此函数后,我从 casablanca 抛出异常,说 uri 无效。
知道如何在 casablanca 中正确构造请求,以便我可以将其发送到 github 服务器吗?
谢谢你。

4

1 回答 1

0

在 GitHub 页面上的示例中,-u username:password有一个 curl 选项:

-u/--user <user:password> 

    Specify the user name and password to use for server authentication.

您可以使用http_client_config::set_credentials().

(另外,请参阅相关问题:在 Casablanca 中设置基本 HTTP 身份验证

于 2016-03-28T21:43:21.860 回答