3

I'm trying to store files into HDFS from an application written in C++. I know you can use curl in command line/terminal:

First send a PUT request,

1) curl -i -X PUT http://<name_node>:50070/webhdfs/v1/<path>?op=CREATE

and then write data to the data node with the redirected address,

2) curl -i -X PUT -T <local path> "http://<data_node>:50075/webhdfs/v1/<path>?op=CREATE...

I want to know how to store data to HDFS directly using libcurl in c++.

Note: I'm able to send GET requests and it all works perfectly:

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

1 回答 1

3

最好使用 curl 以便在步骤 1 之后自动重定向。以下命令适用于我的情况:

curl -L -i -X PUT -T local_file "http://:50075/webhdfs/v1/?op=CREATE...

于 2015-07-09T07:56:22.090 回答