Reputation: 2128
In android 6.0 the org.apache.http.legacy
library is deprecated, so i try to migrate a project to use HttpURLConnection
.
In the project, i used the Header
and the BasicHeader
. I didn't found how i can replace these classes with HttpUrlConnection
. I want just to know how can i add a header in a request using HttpUrlConnection
.
Upvotes: 0
Views: 172
Reputation: 751
URL url=new URL("YOURURL");
HttpURLConnection connection= (HttpURLConnection) url.openConnection();//establishing connection from url
connection.setDoOutput(true);
connection.setRequestMethod("POST");//method type
connection.setRequestProperty("Content-Type","application/json");// setting headers
Upvotes: 2