zoukankan      html  css  js  c++  java
  • curl记录

    curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, content);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(content));
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, m_timeout);//接收数据时超时设置,如果10秒内数据未接收完,直接退出

    if (username != "" && userpass != "")
    {
    char szUserPwd[100] = { 0 };
    _snprintf(szUserPwd, sizeof(szUserPwd), "%s:%s", username.c_str(), userpass.c_str());
    curl_easy_setopt(curl, CURLOPT_USERPWD, szUserPwd);
    }

    struct curl_slist *headers = NULL;
    //headers = curl_slist_append(headers, "Accept: application/json");
    //headers = curl_slist_append(headers, "Content-Type:application/json;charset=UTF-8");
    headers = curl_slist_append(headers, "Content-Type: application/json");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

    res = curl_easy_perform(curl);
    if (res == CURLE_OK)
    {
    iCode = 0;
    }
    else
    {
    iCode = (int)res;
    }
    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);

  • 相关阅读:
    json和xml以及ajax的数据格式用法
    关于PHP数据库mysql的一些案例
    PHP的一些语句 if...else...elseif
    Python中的流程控制(if、while、for)
    Python获取当前系统时间
    Python中格式化输出的三种方式
    Python中如何修改文件
    Python的五大数据类型的作用、定义方式、使用方法
    了解Python
    ~
  • 原文地址:https://www.cnblogs.com/zhangmo/p/14250038.html
Copyright © 2011-2022 走看看