当前位置: 动力学知识库 > 问答 > 编程问答 >

Using Header and BasicHeader with HttpUrlConnection in android

问题描述:

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.


网友答案:
  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
分享给朋友:
您可能感兴趣的文章:
随机阅读: