2016-05-12 12 views
3
< HTTP/1.1 405 Method Not Allowed 

私はPOSIをcurl APIで使用していても、PUTメソッドは許可されていません。ファイルをHTTPサーバーにCプログラムでコピーする

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

    } 
} 
+0

httpを実行しているサーバーにカールがインストールされている必要がありますか? – r4nj4n

+0

@Michaelあなたは何か考えていますか? – r4nj4n

+0

cURLのドキュメントを読んでいますか?特にhttps://curl.haxx.se/libcurl/c/libcurl-tutorial.htmlの 'HTTP POSTing'セクションで、あなたのコードにいくつか不足しているようです – GMichael

答えて

0

ただCURLOPT_POSTのままにして、CURLOPT_UPLOADを削除してください。 this questionを参照してください。

あなたがthis other questionに気づいたように、ハンドルを「ロック」PUTメソッドは、CURLOPT_POSTと次curl_easy_setoptが無効になっていることをCURLOPT_UPLOADを設定するとlibcURLは内部的には、何かをするようです。

関連する問題