I am trying to send a POST request to HTTP endpoint along with a text file. I tried following the instructions in the help documentation provided http://127.0.0.1:63771/help/index.jsp?topic=%2Fcom.cloveretl.gui.docs%2Fdocs%2Fhttpconnector.html%23httpconnector-examples but nothing seems to work.
I received the error message shown below.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>411 Length Required</title>
</head><body>
<h1>Length Required</h1>
<p>A request of the requested method POST requires a valid Content-length.<br />
</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at api.reachcm.com Port 443</address>
</body></html>
||411|
Is there an example out there that simply sends a file with the HTTP POST request?
Not sure which particular example you’re referring to. “Upload a File using Multipart Entities”? I do not believe you need to do that, just choosing input file in this simple case as you outline should be fine.
My best guess would be, “Content-Length” header is not being sent along in which case you can just add this header with proper information using “additionalHTTPHeaders” from “Input mapping”. Try to enable debug logging (Run → Run configurations) to see which headers are being sent with your message.
Thank you for your suggestions. You are absolutely right about the content-length not being sent in the header. I could not quite figure out how to figure out the content length of the file being sent.
http://doc.cloveretl.com/documentation/UserGuide/index.jsp?topic=/com.cloveretl.gui.docs/docs/httpconnector.html
In the link above there is an example of file upload using multipart entities which I could not make it work.
When you said ‘just choosing input file in this simple case as you outline should be fine’, which field name should the file to be uploaded attached to? Do you mean ‘inputFileUrl’? I thought that field takes a file and constructs HTTP request from that file content.
Hi Shubha,
As a user “the_goat” already advised, the HTTP “411 Length Required” client error response code usually indicates that the server refuses to accept the request without a defined Content-Length header. Generally, the Content-Length header should always be set when a POST is involved, therefore, the CloverETL sends the Content-Length automatically based on the content itself. So usually, you don’t need to worry about it. In your case, I believe that the system didn’t have any content available for calculating the Content-Length header.
If your requirement is to simply send a file with the HTTP POST request I don’t believe the function Multipart Entities is really necessary. The multipart messages are used in case you have more different sets of data and you want to combine them in s single body of the request. I believe that you can avoid it entirely.
As you said, the right field to use is the “Input file URL” attribute or “inputfileURL” field within Input Mapping editor.
In accordance with the examples in the documentation, you would need to set up the following in a HTTPConnector component:
URL: http://clover:clover@localhost:8080/your/app/path
Request method: POST
Input file URL: ${DATAIN_DIR}/some.txt
Please give this a try and let me know if it works, or please provide me with more details about the HTTP endpoint you are accessing and its requirements.
Thank you and have a nice day, Eva
@sshrestha: yes, I absolutely do. Though if you choose to use this option (can provide different URL using Input Mapping property), the drawback would be; you have to have file available somewhere on filesystem.
In case, you’re using some sort of serialization (e.g. using JSONWriter) and you actually are using “requestContent” property from Input Mapping, then you should be able to use httpHeaders or rawHttpHeaders property to provide content length manually, I believe application of function length() on that string should be sufficient method.
Would you be able to provide graph you already have, so I can take a look and be less “theoretical”?