Get header from HttpResponse in Android

后端 未结 5 2034
醉话见心
醉话见心 2020-12-31 09:56

Is there a way to get the value of a specific header using the HttpResponse object returned by the HttpClient execute() method in Andr

5条回答
  •  抹茶落季
    2020-12-31 10:37

    There are several ways to get specific headers. HttpResponse inherits from HttpMessage, which provides the following header retrieval methods:

    • Header getFirstHeader(String name)
    • Header[] getHeaders(String name)
    • Header getLastHeader(String name)

    In your case, you probably want getFirstHeader(String). Headers can contain multiple values, hence the Header[] array return from getHeaders(); if you only expect there to be a single header, getFirstHeader(String) should suffice.

提交回复
热议问题