新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > sbc6000x數據采集小應用

        sbc6000x數據采集小應用

        作者: 時間:2011-12-18 來源:網絡 收藏
        #include stdio.h>
        #include string.h>
        #include curl/curl.h
        #include curl/types.h
        #include curl/easy.h
        /*針對sns進行配置,可惜現在digu在維護中,可以自己選擇配置*/
        #define SNS_UPDATE_URL http://api.digu.com/statuses/update.xml /* sns社區開放api入口*/
        #define SNS_USERPWD 用戶名:密碼
        #define SNS_USER 用戶email
        #define PROXY 可設置代理
        int digusendmsg(char *msg)
        {
        CURL *curl;
        CURLcode res;
        printf(Init to send message.n);
        struct curl_httppost *formpost=NULL;
        struct curl_httppost *lastptr=NULL;
        struct curl_slist *headerlist=NULL;
        static const char buf[] = Expect:;
        curl_global_init(CURL_GLOBAL_ALL);
        /*Fill in the file upload field */
        curl_formadd(formpost,
        lastptr,
        CURLFORM_COPYNAME,content,
        CURLFORM_COPYCONTENTS, msg,
        CURLFORM_END);
        curl_formadd(formpost,
        lastptr,
        CURLFORM_COPYNAME,source,
        CURLFORM_COPYCONTENTS,mx,
        CURLFORM_END);
        curl = curl_easy_init();
        printf(Init done!n);
        headerlist = curl_slist_append(headerlist, buf);
        if(curl) {
        /* what URL that receives this POST */
        curl_easy_setopt(curl, CURLOPT_VERBOSE,1L);
        curl_easy_setopt(curl,CURLOPT_PROXY,PROXY);/* http代理設置,如果沒有可以注釋掉*/
        curl_easy_setopt(curl,CURLOPT_URL,SNS_UPDATE_URL);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER,headerlist);
        curl_easy_setopt(curl, CURLOPT_HTTPPOST,formpost);
        curl_easy_setopt(curl, CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
        curl_easy_setopt(curl,CURLOPT_USERPWD,SNS_USERPWD);
        curl_easy_setopt(curl, CURLOPT_HEADER, 1);
        curl_easy_setopt(curl, CURLOPT_COOKIE,SNS_USER);
        res = curl_easy_perform(curl);
        /* always cleanup */
        curl_easy_cleanup(curl);
        /* then cleanup the formpost chain */
        curl_formfree(formpost);
        /* free slist */
        curl_slist_free_all (headerlist);
        if(!res){
        printf(TranlateOK!n);
        return0;
        }else{
        printf(Tranlateerror!n );
        return-1;
        }
        }
        }
        而從不同接口接受到的數據,就可以直接使用snsendmsg函數進行傳輸到SNS社區就可以了。
        一個非常簡單的J..
        上一頁 1 2 下一頁

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 蕉岭县| 留坝县| 黔西| 山东| 永新县| 蒲城县| 平利县| 西吉县| 鹿泉市| 若羌县| 江安县| 大冶市| 武平县| 景泰县| 秭归县| 门头沟区| 江安县| 牡丹江市| 定日县| 林甸县| 曲麻莱县| 贵溪市| 黔西县| 沽源县| 罗源县| 梁平县| 白银市| 阳曲县| 南昌市| 黄石市| 东兴市| 广河县| 温宿县| 顺平县| 花莲市| 恩平市| 西平县| 塔河县| 嘉峪关市| 晋城| 紫金县|