I'm using the HttpConnection class in Java to send HTTP requests.
How do I omit unwanted HTTP headers? like:
If you are talking about HttpURLConnection, you can't do it. Once the header is set, it can't be removed.
Setting header to null or empty doesn't work. I tried this before on Java 5, it resulted invalid HTTP headers, like
Content-Type: text/html
User-Agent
Content-Length: 123
Yes, setRequestProperty in URLConnection
import java.net.URL;
import java.net.URLConnection;
URL url = new URL("http://www.example.com");
URLConnection urlc = url.openConnection();
urlc.setRequestProperty("User-Agent", null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With