Wenyi Li
Wenyi Li

Reputation: 47

sending PUT request using libcURL without data

I am trying to interface with Amazon Cloud Backup RESTful API. And in order to remove a file on server side, I need to use a PUT request.

Below shell scripts works well:

curl -v -X PUT https://cdws.us-east-1.amazonaws.com/drive/v1/trash/161kKftTTTuRee1hicOhAw --header "Authorization: Bearer Atza|IQEBLjAsAhQ5zx7pKp9PCgCy6T1JkQjHHOEzpwIUQM"

But now I want to realize it using libcURL. And below is my code:

int curlRequest(char *url, char *header){
    CURL *curl;
    CURLcode res;
    struct curl_slist *chunk=NULL;
    curl_global_init(CURL_GLOBAL_DEFAULT);
    curl=curl_easy_init();
    if(curl){
        chunk=curl_slist_append(chunk, header);
        curl_easy_setopt(curl, CURLOPT_HTTPHEAD, chunk);
        curl_easy_setopt(curl, CURLOPT_PUT, 1L);
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        res=curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        curl_slist_free_all(chunk);
    }
    Return 0;
}

Then I got a reply as follow and the program keep waiting:

< HTTP/1.1 100 Continue

I know that if I upload file using PUT method, I need to use CURLOPT_READFUNCTION. But actually I do not need to upload any data. How can I fix this issue?

Upvotes: 0

Views: 659

Answers (1)

Mark Trinh
Mark Trinh

Reputation: 452

I had this same issue. You need to use this:

curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); 

instead of:

curl_easy_setopt(curl, CURLOPT_PUT, 1L);

Upvotes: 2

Related Questions