私はちょうど好奇心の質問があります。私はこのコードを実行するとHttpServletRequestはhttppostからパラメータを取得しません
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Enumeration en = request.getParameterNames();
while (en.hasMoreElements()){
System.out.println(en.nextElement());
}
}
:私は要求をリッスンし、パラメータを解析し、サーブレットを持って、私のサーバー側で
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(getString(R.string.url));
//This code does not work
HttpParams params = new BasicHttpParams();
params.setParameter("type", "20");
post.setParams(params);
try {
HttpResponse response = client.execute(post);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
:私はこのようになりますアンドロイドでHttpPost要求を持っていますサーブレットにはパラメータがまったく表示されません。しかし、 "パラメータ"チャンク全体をこのコードで置き換えた場合、
//This code works
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("type", "20"));
try {
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
私のサーブレットはパラメータを解析できます。それは問題ではない、私はただエンティティを使用するつもりだが、私の質問は、なぜ私のサーブレットが最初のコードチャンクからパラメータを取得できないのですか? setParamsの何が問題なの?サーブレットをエンティティにすると、サーブレットでパラメータが表示されるのはなぜですか?
これは本当に良い説明です!ありがとう、ちょうど私が欲しいものです。 – Otra