Skip to content Skip to sidebar Skip to footer

Add Header To Post Request In String

I'm using that code to send POST requests. Now i need to add header to this, any ways of doing it? In Google most ways is to use another methods, like HttpPost and addHeader method

Solution 1:

Do code like this:

HttpUrlConnectionmyURLConnection= (HttpUrlConnection)conn;
  myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  myURLConnection.setRequestProperty("Content-Length", "" + postData.getBytes().length);
  myURLConnection.setRequestProperty("Content-Language", "en-US");

add this after line:

URLConnectionconn= url.openConnection();

and here "Content-Type", "Content-Length", "Content-Language" are headers here.

Thanks and let me know if need more.

happy Coding!!

Post a Comment for "Add Header To Post Request In String"