zoukankan      html  css  js  c++  java
  • curl post请求

    libcurl发送post请求,包括httpheader参数

    static size_t getCharCode(void *ptr, size_t size, size_t nmemb, void *userdata)
    {
        string *version = (string*)userdata;
        version->append((char*)ptr, size * nmemb);
        return (size * nmemb);
    }
    
    void sendpost()
    {
      string result = "";
        CURL *handle = curl_easy_init();
        if (! handle)
        {
            CCLOG("can not init curl");
            return;
        }
        curl_easy_setopt(handle, CURLOPT_URL, "you_url_path");
        curl_easy_setopt(handle, CURLOPT_HEADER, 0);
        curl_easy_setopt(handle, CURLOPT_POST, 1);
        curl_easy_setopt(handle, CURLOPT_POSTFIELDS,token.c_str());
        curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);
        
        struct curl_slist *slist  =  NULL;
        slist  =  curl_slist_append(slist, "param:1");
        slist  =  curl_slist_append(slist, "param:2");
    
        curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
        curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, getCharCode);
        curl_easy_setopt(handle, CURLOPT_WRITEDATA, &result);
        CURLcode res = curl_easy_perform(handle);
        if (res == CURLE_OK)
        {
    
        }
        curl_easy_cleanup(handle);
    }
  • 相关阅读:
    接口
    java基础
    java的反射
    按照字典序打印所有的字符串
    求幂的问题
    时间复杂度与空间复杂度
    孩子们的游戏(圆圈中最后剩下的数)
    约瑟夫环问题
    翻转单词顺序列
    复杂链表的复制
  • 原文地址:https://www.cnblogs.com/howeho/p/3780371.html
Copyright © 2011-2022 走看看