首 页文档资料下载资料维修视频包年699元
请登录  |  免费注册
当前位置:精通维修下载 > 文档资料 > 家电技术 > 维修教程知识 > 单片机栏
sbc6000x数据采集到互联网SNS社区的小应用
来源:本站整理  作者:佚名  2010-02-15 00:38:33



#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] 

关键词:

·上一文章:基于多嵌入式处理器实现的牵引理疗系统
·下一文章:基于FPGA的高速定点FFT算法的设计方案
[] [返回上一页] [打 印]

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分)

推荐阅读

图文阅读

热门阅读

Copyright © 2007-2017 down.gzweix.Com. All Rights Reserved .
页面执行时间:269,351.60000 毫秒