我需要通过 HttpPost 方法使用 HttpClient 提供一个简单的登录。这就是我所拥有的:
DefaultHttpClient httpclient = new DefaultHttpClient();
String url = "http://10.20.128.47/ilias/ilias.php?lang=de&client_id=0001&cmd=post&cmdClass=ilstartupgui&cmdNode=jt&baseClass=ilStartUpGUI&rtoken=";
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("username", "client01"));
formparams.add(new BasicNameValuePair("password", "client01"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
HttpPost httppost = new HttpPost(url);
httppost.setEntity(entity);
它似乎不起作用。我正在使用“action =” - 该登录页面上 html 代码中的 url。我可以毫无问题地做一个 HttpGet。
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
这给了我想要的登录页面。所以我想执行 HttpPost 方法,它会让我登录,然后我想做一个 HttpGet,它给我登录用户的 http 代码。有人可以帮我吗?我究竟做错了什么?谢谢