gpt4 book ai didi

通过C程序复制一个文件到HTTP Server

转载 作者:行者123 更新时间:2023-12-04 12:29:00 24 4
gpt4 key购买 nike

< HTTP/1.1 405 Method Not Allowed

即使我在 curl API 中使用 POSt,它也说不允许 PUT 方法。

< Date: Fri, 20 May 2016 11:03:06 GMT
* Server Apache/2.2.15 (CentOS) is not blacklisted
< Server: Apache/2.2.15 (CentOS)
< Allow: GET,HEAD,POST,OPTIONS,TRACE
< Content-Length: 318
< Connection: close
< Content-Type: text/html; charset=iso-8859-1

在尝试使用 HTTP POST 时出现上述错误。下面是我正在尝试的代码

  curl = curl_easy_init();
if(curl) {
/* upload to this place */
curl_easy_setopt(curl, CURLOPT_URL, url);

curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
/* tell it to "upload" to the URL */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_POST, 1L);

// curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);

/* set where to read from */
curl_easy_setopt(curl, CURLOPT_READDATA, fd);

/* and give the size of the upload (optional) */
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);

/* enable verbose for easier tracing */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));

}
}

最佳答案

只保留 CURLOPT_POST 并删除 CURLOPT_UPLOAD。参见 this question .

当您设置 CURLOPT_UPLOAD 将 PUT 方法“锁定”到句柄时,libcURL 似乎在内部做了一些事情,如 this other question 中所述,使以下带有 CURLOPT_POST 的 curl_easy_setopt 无效。

关于通过C程序复制一个文件到HTTP Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37180257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com