Android - Как получить заголовок в ответ, используя asynctask android - PullRequest
0 голосов
/ 09 октября 2018

Я использовал этот код.Теперь я хочу получить заголовок в ответ.Как я могу это сделать?

HttpURLConnection conn = (HttpURLConnection) url_.openConnection();
conn.setRequestMethod("GET");
InputStream in = new BufferedInputStream(conn.getInputStream());
String jsonStr = convertStreamToString( in );

public static String convertStreamToString(InputStream input) throws Exception {
  BufferedReader reader = new BufferedReader(new InputStreamReader(input));
  StringBuilder sb = new StringBuilder();
  String line = null;

  while ((line = reader.readLine()) != null) {
    sb.append(line);
  }

  input.close();
  return sb.toString();
}

Снимок экрана:

enter image description here

1 Ответ

0 голосов
/ 03 апреля 2019

я получаю ответ:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet("https://api***********.php");
HttpResponse httpResponse = httpclient.execute(httpPost);
Header[] headers = httpResponse.getAllHeaders();
String Token="";

for (Header header : headers) {

  System.out.println("Key : " + header.getName()+ " ,Value : " + header.getValue());

    if (header.getName().equals("your_parm_key")) {

       Token = header.getValue();

       }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...