2

如何从以下代码收到的 http 200 OK 响应中提取特定的 http 标头值(例如:Set-Cookie:auth=xyzabc) -

public void sendPost() {
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://172.26.207.10/myexample/webauth/auth_default_submit");

// Set User-Agent and any other headers you want
// Note: you don't have to set most of the headers manually, for example Content-Type and Content-Length
post.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Firefox/24.0");
post.setHeader("Referer", "http://xxx.xxx.xxx.xx/myexample/webauth/auth_default?app_name=SampleWebAppTesting");

// Add the parameters
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("pincode", "9381"));
parameters.add(new BasicNameValuePair("response", "allow"));
parameters.add(new BasicNameValuePair("token", "dc7553b7d7910e51e331d5c3245133ba90b135da1504299510e91984f4e2cf81"));
post.setEntity(new UrlEncodedFormEntity(parameters));

// Do the actual post
HttpResponse response = httpClient.execute(post);

// Read the response
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
StringBuffer responseBuffer = new StringBuffer();
while ((line = rd.readLine()) != null) {
    responseBuffer.append(line);
}
rd.close();

// Print the results
System.out.println(responseText.toString());

}

4