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);

  • 相关阅读:
    linux虚拟机上网
    asp 两种方法连接sql sever 并显示
    了解ado.net 的相关内库--读书笔记
    win10固态硬盘分区方法
    sql sever2012安装错误,无效的十六进制字符
    python学习笔记3
    python 学习笔记4
    python学习笔记2
    20189319《网络攻防》第十周作业
    20189319《网络攻防》第九周作业
  • 原文地址:https://www.cnblogs.com/zhangmo/p/14250038.html
Copyright © 2011-2022 走看看