我想從Java Web應用程序使用頭向Android發送響應。我無法讀取標題值。如何檢索Android中的標題值?
我傳球頭球爲:
response.setHeader("response", "ok");
response.setHeader("url", androidResponseBean.getUrl());
我試着使用:
Header[] header = (Header[]) httpResponse.getAllHeaders();
我無法重複用於檢索標頭值。
這是我的代碼,它發送請求的Web應用程序:
DefaultHttpClient httpClient = new DefaultHttpClient();
//HttpGet httpGet = new HttpGet(params[0]);
HttpPost httpPost = new HttpPost(params[2]);
ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("ssn", params[0]));
nameValuePair.add(new BasicNameValuePair("dob",params[1]));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8"));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
你可以使用正則表達式從頭部檢索字段的值 – Raghunandan
刪除'android-asynctask'標記,因爲問題與此標記無關 –