已编辑:Java httpPost into .asp form
我正在创建一个应用程序,它将显示来自网站的一些信息,即.asp,以访问我必须登录的一些数据。如何将我的凭据(登录名,密码)发布到服务器并获取页面作为回报。当我登录时,我也认为路上有很多重定向。我不知道asp。我正在做什么,我只是将用户名,密码发布到服务器,我可以在正确的位置检索该页面的源代码和我发布的信息。但接下来我该怎么办? 我认为可以有一个可以与任何.asp网站引擎一起使用的代码段。
编辑:好的,收到了页码 身份验证表单属于IIS类型。
指定nameValuePairs时使用html输入(名称,值)对。
登录表单:
<form method="post" id="form1" name="form1" action="">
<input id="txtUser" name="txtUser" type="text" size="13" value="" />
<input id="txtPassword" name="txtPassword" type="password" size="13" value="" />
<input id="BLogin" name="BLogin" type="submit" value="Log in" />
<input type="checkbox" id="chkSave" name="chkSave"/>
</form>
一些JAVA:
HttpPost httppost = new HttpPost("WEBSITE WITH LOGIN PAGE (Ex: www.qwerty.asd/login.asp)");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("txtUser", "YOUR LOGIN NAME"));
nameValuePairs.add(new BasicNameValuePair("txtPassword", "YOUR PASSWORD"));
nameValuePairs.add(new BasicNameValuePair("BLogin", "Log in"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println("Post logon cookies:");
cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i));
// httpclient.getCookieStore().addCookie(cookies.get(i));
}
}
获取标题:
Header[] headers = response.getAllHeaders();
for(int i=0; i<headers.length; i++){
//System.out.println(headers[i]);
Header h = headers[i];
System.out.println(h.getName());
System.out.println(h.getValue());
}
继续进入同一服务中的任何其他页面:
HttpPost request2 = new HttpPost(
"www.qwerty.asd/information.asp");
response = httpclient.execute(request2);
String responseBody2 = EntityUtils.toString(response.getEntity());
//System.out.println(responseBody2);
if (entity != null) {
entity.consumeContent();
}
要让Android Webview显示网页:
WebView.loadData(responseBody2, "text/html", "utf-8");
答案 0 :(得分:1)
.asp与Android无直接关系。
您希望使用WebView制作标准HTTP REST请求。
此外,这是一个包含Android中许多常见任务的页面,以及许多教程,文章和代码示例的链接:http://developer.android.com/resources/faq/commontasks.html
编辑:许多人可能会说使用带登录按钮的标准警报对话框但我不相信警报对话框,因为它们有问题。要查看示例,请创建一个不执行任何操作并更改屏幕方向的简单对话框...它看起来似乎不错但是如果您查看LogCat,您会看到它泄漏了活动。
因此,我建议您在清单中的活动代码中创建一个常规活动并使用android:theme =“@ android:style / Theme.Dialog”,以使活动看起来像一个对话框。
答案 1 :(得分:0)
鲍里斯 给你问题,请尝试以下。