[英]how to post (parameters) and get the response from Httpclient and Httppost in android
[英]How to perform a Login unsing HttpPost method. What Parameters Do I have to send in the Post, and how can I Get the response
我需要通過HttpPost方法使用HttpClient提供一個簡單的Login。 這就是我所擁有的:
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代碼。 有人可以幫我嗎? 我究竟做錯了什么? 謝謝
你不是忘了打電話嗎
響應= httpclient .execute(httppost);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.