saplingPro
saplingPro

Reputation: 21329

How do I send request headers?

How do I send request headers ? Suppose I want to send my own request header when I make an HTTP request to a website.

How do I do that ?

URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

// HOW DO I SEND REQUEST HEADER LIKE Date,Cookie,Cache-Control ???

Upvotes: 0

Views: 180

Answers (2)

Francis
Francis

Reputation: 1090

connection.setRequestProperty("HeaderName", "Value");

Upvotes: 2

Keerthivasan
Keerthivasan

Reputation: 12890

After getting the HttpURLConnection connection, you can do that as follows

//adding headers
con.setRequestProperty("headername", value);

Upvotes: 2

Related Questions