title: Send cURL PUT command to create file in webhdfs programatically in c++ using libcurl
body: <p>I'm trying to store files into HDFS from an application written in C++. I know you can use curl in command line/terminal:</p>
  
  <p>First send a PUT request,</p>
  
  <pre><code>1) curl -i -X PUT http://&lt;name_node&gt;:50070/webhdfs/v1/&lt;path&gt;?op=CREATE
  </code></pre>
  
  <p>and then write data to the data node with the redirected address,</p>
  
  <pre><code>2) curl -i -X PUT -T &lt;local path&gt; "http://&lt;data_node&gt;:50075/webhdfs/v1/&lt;path&gt;?op=CREATE...
  </code></pre>
  
  <p>I want to know how to store data to HDFS directly using libcurl in c++.</p>
  
  <p>Note: I'm able to send GET requests and it all works perfectly:</p>
  
  <pre><code>string url = "http://localhost:50070/webhdfs/v1/mydata/restAPI.txt?op=GETCONTENTSUMMARY"    
  if (curl)
          {
              curl_easy_setopt(curl, CURLOPT_URL, url1.c_str());
              result = curl_easy_perform(curl);
              curl_easy_cleanup(curl);
          }
  </code></pre>