3
< HTTP/1.1 405 Method Not Allowed
即使我在curl API中使用POSt,它說PUT方法是不允許的。通過C程序將文件複製到HTTP服務器
< 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));
}
}
我需要curl安裝在運行http的服務器上嗎? – r4nj4n
@Michael你有什麼想法嗎? – r4nj4n
您是否閱讀過cURL文檔?特別是https://curl.haxx.se/libcurl/c/libcurl-tutorial.html的'HTTP POSTing'部分似乎錯過了代碼中的一些東西 – GMichael