Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove a header from URLConnection

I am talking to a file upload service that accepts post data, not form data. By default, java's HttpURLConnection sets the Content-Type header to application/x-www-form-urlencoded. this is obviously wrong if i'm posting pure data.

I (the client) don't know the content type. I don't want the Content-Type header set at all. the service has a feature where it will guess at the content type (based on the file name, reading some data from the file, etc).

How do I unset a header? There's no remove header, and setting it to null doesn't change the value and setting it to the empty string results in the header being set with no value.

like image 335
Jeffrey Blattman Avatar asked Jan 17 '13 03:01

Jeffrey Blattman


1 Answers

I haven't tested this approach but you can try this:

Extend HttpURLConnection and try by overriding its getContentHandler() and setContentHandler(...) methods. Most probably this should work as, you will take a look at code of getContentHandler().

like image 177
Prateek Avatar answered Oct 23 '22 03:10

Prateek