【问题标题】:C LibCurl file upload to ruby on rails serverC LibCurl文件上传到rails服务器上的ruby
【发布时间】:2017-04-20 18:51:09
【问题描述】:

我正在尝试将文本文件上传到 ruby​​ on rails 服务器。我通过 CLI 成功上传文件:

curl -X POST --data-urlencode data@/etc/filepath/ www.example.com/path

现在,尝试通过 C: 使用 libCurl:

        FILE *fd;
        fd = fopen(file_path, "rb");
        if (!fd)
            return -1;

        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        curl_easy_setopt(curl, CURLOPT_POST, 1L);
        curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
        curl_easy_setopt(curl, CURLOPT_READDATA, fd);
    }

任何想法为什么通过 CLI 运行可以工作,但 libCurl 不能?我是否缺少一些 curl 选项或者我的服务器是否需要备用配置?

谢谢

【问题讨论】:

    标签: ruby-on-rails c curl libcurl


    【解决方案1】:

    基本上你想要CURLOPT_POSTFIELDS CURLOPT_UPLOAD。您想将数据作为字符串提供还是从文件中读取?

    你也不想要bothCURLOPT_POSTCURLOPT_UPLOAD,因为后者暗示PUT

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 1970-01-01
      • 2019-06-24
      • 2011-02-19
      • 2011-05-23
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多