当前位置:编程学习 > JAVA >>

HttpGet发送用户名和密码

android应用程序获取http网页数据,网页有密码
用HttpGet 在url后面加password不管用


	public void onClick(View v) {
new Thread(){
public void run(){
String uriApi="http://oem.card/publicdir/index.htm?password=0000";
HttpGet httpRequest = new HttpGet(uriApi);
try{
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
if(httpResponse.getStatusLine().getStatusCode() == 200)
{
String strResult = EntityUtils.toString(httpResponse.getEntity());
System.out.println("get strResult="+strResult);
}
else
{
mTextView.setText("Error Response:"+httpResponse.getStatusLine().toString());
}
}catch(ClientProtocolException e){
mTextView.setText(e.getMessage().toString());
e.printStackTrace();
} catch (IOException e) {
mTextView.setText(e.getMessage().toString());
e.printStackTrace();
}catch(Exception e){
mTextView.setText(e.getMessage().toString());
e.printStackTrace();
}
}
}.start();
}

返回的数据是登陆界面的。网站用户名打开网页的时候已经有了 HttpGet --------------------编程问答-------------------- 应该没有问题,你添加网络访问了吗?
<uses-permission android:name="android.permission.INTERNET"/>   --------------------编程问答--------------------
引用 1 楼 fangmingshijie 的回复:
应该没有问题,你添加网络访问了吗?
<uses-permission android:name="android.permission.INTERNET"/>  

添加了的,可以访问网络的 --------------------编程问答-------------------- 你这句话“网站用户名打开网页的时候已经有了”有很大问题啊

即使它已经有了,你就可以不提交这个参数么?你想想手工登陆的过程,这个“已经有了”的参数不也一起提交了么?无论在页面上有没有,你不提交后台就获取不到

另外,不知道后台是怎么处理的,有可能它要求必须是一个POST请求。
或者在打开页面时传来了一个cookies,必须回传这个cookies才允许登陆呢? --------------------编程问答-------------------- 用户名不需要传啊? --------------------编程问答-------------------- 学习学习,用户名需不需要传? --------------------编程问答-------------------- 直接爬虫,模拟浏览器登录
java htmlunit 

引用 楼主 colwer 的回复:
android应用程序获取http网页数据,网页有密码
用HttpGet 在url后面加password不管用


	public void onClick(View v) {
new Thread(){
public void run(){
String uriApi="http://oem.card/publicdir/index.htm?password=0000";
HttpGet httpRequest = new HttpGet(uriApi);
try{
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
if(httpResponse.getStatusLine().getStatusCode() == 200)
{
String strResult = EntityUtils.toString(httpResponse.getEntity());
System.out.println("get strResult="+strResult);
}
else
{
mTextView.setText("Error Response:"+httpResponse.getStatusLine().toString());
}
}catch(ClientProtocolException e){
mTextView.setText(e.getMessage().toString());
e.printStackTrace();
} catch (IOException e) {
mTextView.setText(e.getMessage().toString());
e.printStackTrace();
}catch(Exception e){
mTextView.setText(e.getMessage().toString());
e.printStackTrace();
}
}
}.start();
}

返回的数据是登陆界面的。网站用户名打开网页的时候已经有了
--------------------编程问答--------------------
引用 3 楼 owen1759 的回复:
你这句话“网站用户名打开网页的时候已经有了”有很大问题啊

即使它已经有了,你就可以不提交这个参数么?你想想手工登陆的过程,这个“已经有了”的参数不也一起提交了么?无论在页面上有没有,你不提交后台就获取不到

另外,不知道后台是怎么处理的,有可能它要求必须是一个POST请求。
或者在打开页面时传来了一个cookies,必须回传这个cookies才允许登陆呢?

这个不传貌似是可以的,用户名是固定好了的 --------------------编程问答-------------------- 问题解决了
抓包发现点击登陆的时候
00:00:00.000 POST 302 改向到 http://oem.card/publicdir/sendurl
原来url跳变了,用跳变后的地址加密码就行了
http://oem.card/publicdir/sendurl?
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,