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

  • 相关阅读:
    预警:亚马逊出售的监控摄像机存在预装恶意软件
    opendaylight+openvswitch环境部署
    keepalived+nginx实现高可用
    Huawei ipv6 bgp配置
    F5配置http跳转https
    F5配置ssl卸载
    IBGP路由重分布进IGP路由
    H3C NQA 配置
    Cisco N7K第三方光模块的使用
    Cisco C3850交换机重启后配置无法保存的故障处理
  • 原文地址:https://www.cnblogs.com/zhangmo/p/14250038.html
Copyright © 2011-2022 走看看