携带cookies通过路由器密码验证并对路由器进行配置

看了很多大神的帖子,使用了自己抓到的cookies并且携带它访问路由器配置页面,但还是出现了“no acess”的错误,已经搞了很久了,还是不知道哪里错了。我也想过先向路由器登陆界面传参数,可是抓不到get的参数名。
这是代码

import java.io.ObjectInputStream.GetField;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.impl.cookie.BasicClientCookie2;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

/**

  • 加入了cookies进行登陆,但仍然出现了403错误。
  • @author Administrator * */

public class Main {

public static void main(String[] args) throws Exception {
    //新建cookies
    BasicClientCookie2 cookie = new BasicClientCookie2("Authorization", "Basic%20YWRtaW46MTExMTEx"); 
    cookie.setDomain("192.168.1.1");
    cookie.setPath("/");
    BasicClientCookie cookie2 = new BasicClientCookie("ChgChgPwdSubTag", "");
    cookie2.setDomain("192.168.1.1");
    cookie2.setPath("/");

    //新建一个httpclient
    DefaultHttpClient httpclient=new DefaultHttpClient();
    BasicCookieStore basicCookieStore = new BasicCookieStore();
    basicCookieStore.addCookie(cookie);

    httpclient.setCookieStore(basicCookieStore);
    System.out.println(basicCookieStore.getCookies().get(0).getName());
    System.out.println(basicCookieStore.getCookies().add(cookie2));
    System.out.println(basicCookieStore.getCookies().get(0).getValue());
    HttpGet get = new HttpGet("http://192.168.1.1/userRpm/VirtualServerRpm.htm");
    HttpResponse response = httpclient.execute(get);


    if(response.getStatusLine().getStatusCode()==200){//如果状态码为200,就是正常返回
        String result=EntityUtils.toString(response.getEntity());
        //得到返回的字符串
        System.out.println(result);
    }
}

}

2个回答

构造参数不对 先用浏览器登录 然后自己抓包对比浏览器发送的数据

构造柱方法不对,抓包分析你的程序发出的报文和浏览器发出的报文的cookie有何不同。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐