Setting custom header using HttpURLConnection

前端 未结 2 1265
难免孤独
难免孤独 2021-02-14 06:57

I am simply making a GET request to a Rest API using HttpURLConnection.

I need to add some custom headers but I am getting null wh

2条回答
  •  情书的邮戳
    2021-02-14 07:35

    The conn.getHeaderField("CustomHeader") returns the response header not the request one.

    To return the request header use: conn.getRequestProperty("CustomHeader")

提交回复
热议问题