如何使用java登录此站点?
我试图使用HttpClient登录此站点: 经过一整天的尝试,我就是无法获得登录页面。这是我的代码:如何使用java登录此站点?,java,debugging,web-scraping,httpclient,Java,Debugging,Web Scraping,Httpclient,我试图使用HttpClient登录此站点: 经过一整天的尝试,我就是无法获得登录页面。这是我的代码: public class SimpleClient { static String code = ""; static String captchaUrl= "https://passport.wiitrans.cn/code"; public static void logIn() throws IOException { CloseableHttp
public class SimpleClient {
static String code = "";
static String captchaUrl= "https://passport.wiitrans.cn/code";
public static void logIn() throws IOException {
CloseableHttpClient httpclient = HttpClients.createDefault();
// HttpGet httpGet = new HttpGet("https://passport.wiitrans.cn/");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("account", xxxxx));
formparams.add(new BasicNameValuePair("password", xxxxx));
formparams.add(new BasicNameValuePair("code", code));
formparams.add(new BasicNameValuePair("autologin", "1"));
UrlEncodedFormEntity entity1 = new UrlEncodedFormEntity(formparams, "UTF-8");
HttpPost httppost = new HttpPost("https://passport.wiitrans.cn/");
httppost.setEntity(entity1);
HttpResponse response = httpclient.execute(httppost);
String set_cookie = response.getFirstHeader("Set-Cookie").getValue();
System.out.println(set_cookie.substring(0, set_cookie.indexOf(";")));
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++=");
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++=");
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++=");
HttpGet httpget = new HttpGet("https://translator.wiitrans.cn/");
httpget.setHeader("Cookie", set_cookie);
HttpResponse response2 = httpclient.execute(httpget);
HttpEntity entity2 = response2.getEntity();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity2.getContent()));
String line = "";
while((line = bufferedReader.readLine()) != null){
System.out.println(line);
}
}
public static void main(String[] args){
code = Captcha.getCaptcha(captchaUrl);
try {
logIn();
} catch (IOException e) {
e.printStackTrace();
}
}
}
公共类SimpleClient{
静态字符串代码=”;
静态字符串captchaUrl=”https://passport.wiitrans.cn/code";
public static void logIn()引发IOException{
CloseableHttpClient httpclient=HttpClients.createDefault();
//HttpGet HttpGet=新的HttpGet(“https://passport.wiitrans.cn/");
List formparams=new ArrayList();
formparams.add(新的BasicNameValuePair(“账户”,xxxxx));
formparams.add(新的BasicNameValuePair(“密码”,xxxxx));
formparams.add(新的BasicNameValuePair(“代码”,代码));
formparams.add(新的BasicNameValuePair(“自动登录”,“1”));
UrlEncodedFormEntity entity1=新的UrlEncodedFormEntity(formparams,“UTF-8”);
HttpPost HttpPost=新的HttpPost(“https://passport.wiitrans.cn/");
httppost.setEntity(entity1);
HttpResponse response=httpclient.execute(httppost);
字符串set_cookie=response.getFirstHeader(“set cookie”).getValue();
System.out.println(set_cookie.substring(0,set_cookie.indexOf(“;”));
System.out.println(“++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=”;
System.out.println(“++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=”;
System.out.println(“++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=”;
HttpGet HttpGet=新的HttpGet(“https://translator.wiitrans.cn/");
setHeader(“Cookie”,set_Cookie);
HttpResponse response2=httpclient.execute(httpget);
HttpEntity entity2=response2.getEntity();
BufferedReader BufferedReader=new BufferedReader(new InputStreamReader(entity2.getContent());
字符串行=”;
而((line=bufferedReader.readLine())!=null){
系统输出打印项次(行);
}
}
公共静态void main(字符串[]args){
代码=验证码。获取验证码(captchaUrl);
试一试{
登录();
}捕获(IOE异常){
e、 printStackTrace();
}
}
}
验证码是手动下载和输入的,有人能帮我解决这个问题吗?您如何知道要在登录请求中发送的验证码?编辑:验证码是手动下载和输入的。登录url是
https://passport.wiitrans.cn/Login/login
。您应该在表单数据中发送帐户
、密码
(加密)、代码
和自动登录
code
是图像中显示的验证码。不知道如何从验证码图像获取登录代码