小编zom*_*bor的帖子

libcurl 404检测

我在我的c ++程序中使用libcurl进行文件下载.如何检测请求是否为404,而不是写入文件?代码是:

    void GameImage::DownloadImage(string file_name) {
    string game_name;
    game_name = file_name.substr(file_name.find_last_of("/")+1);

    CURL *curl;
    FILE *fp;
    CURLcode res;
    string url = "http://site/"+game_name+".png";
    string outfilename = file_name+".png";
    cout<<"INFO; attempting to download "<<url<<"..."<<endl;
    curl = curl_easy_init();
    if (curl) {
        cout<<"INFO; downloading "<<url<<"..."<<endl;
        fp = fopen(outfilename.c_str(), "wb");
        cout<<"INFO; trying to open "<<outfilename<<" for file output"<<endl;
        if (fp != NULL) {
            curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, GameImage::WriteData);
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
            curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
            curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
            res = curl_easy_perform(curl);

            long http_code = 0;
            curl_easy_getinfo (curl, …
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
1
解决办法
5837
查看次数

通过javascript访问OAuth2令牌的正确方法

我理解oauth的基础知识,之前我曾在应用程序中使用它,但从来没有这样.

我写了一个基于oauth2的api,我正在编写一个javascript应用程序(在backbone.js中),我想用它来访问api.

我的问题是我需要为js app获取访问令牌.通常情况下,我会请求类似的令牌example.com/oauth2/token?client_id=<client-id>&client_secret=<client-secret>&....

如果我的客户秘密应该是,好吧,秘密,我应该把它放在我的应用程序js中吗?

通过javascript执行oauth2的正确方法是什么?

我的用户/应用程序也是oauth的"来源",因此我不打算进行任何类型的第三方用户身份验证,因为他们已经登录到网站.

javascript oauth-2.0

5
推荐指数
1
解决办法
1435
查看次数

标签 统计

c++ ×1

javascript ×1

oauth-2.0 ×1