通过casablanca库与github API交互

时间:2016-03-27 15:46:43

标签: c++ github casablanca

我正在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());  

在打电话给我之后,我从卡萨布兰卡那里得到异常,说uri无效 知道如何在卡萨布兰卡正确构建请求,以便将其发送到github服务器吗? 谢谢。

1 个答案:

答案 0 :(得分:0)

在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执行基本身份验证。

(另请参阅相关问题:Set Basic HTTP Authentication in Casablanca