通过casablanca库与github API交互

Interacting with github API through casablanca library

本文关键字:API 交互 github 库与 casablanca 通过      更新时间:2023-10-16

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

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

现在,我试着用微软的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());  

在调用这个之后,我收到了卡萨布兰卡抛出的异常,说uri无效
知道如何在casablanca中正确构建请求,以便将其发送到github服务器吗
非常感谢。

在GitHub页面上的示例中,-u username:password是卷曲的选项:

-u/--user <user:password> 
    Specify the user name and password to use for server authentication.

您可以使用http_client_config::set_credentials()使用C++REST SDK执行基本身份验证。

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