使用Java应用程序登录到hotfile
我想用我的Java应用程序登录并提供文件服务; 我使用Apache使用Java应用程序登录到hotfile,java,apache-httpclient-4.x,Java,Apache Httpclient 4.x,我想用我的Java应用程序登录并提供文件服务; 我使用Apache public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("http://www.hotfile.com/"); HttpResponse response = httpc
public static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://www.hotfile.com/");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println("Initial set of cookies:");
List<Cookie> 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).toString());
}
}
HttpPost httpost = new HttpPost("http://www.hotfile.com/index.php");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("user", "myuser"));
nvps.add(new BasicNameValuePair("pass", "mypass"));
nvps.add(new BasicNameValuePair("returnto", "/"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
System.out.println("Response " + response.toString());
entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
InputStream is = entity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String str = "";
while ((str = br.readLine()) != null) {
System.out.println("" + str);
}
}
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).toString());
}
}
httpclient.getConnectionManager().shutdown();
}
publicstaticvoidmain(字符串[]args)引发异常{
DefaultHttpClient httpclient=新的DefaultHttpClient();
HttpGet HttpGet=新的HttpGet(“http://www.hotfile.com/");
HttpResponse response=httpclient.execute(httpget);
HttpEntity=response.getEntity();
System.out.println(“登录表单get:+response.getStatusLine());
如果(实体!=null){
entity.consumercontent();
}
System.out.println(“cookies的初始集:”);
列表cookies=httpclient.getCookieStore().getCookies();
if(cookies.isEmpty()){
系统输出打印项次(“无”);
}否则{
对于(int i=0;i
但它不起作用。如何登录这些网站?使用他们的API,mate 例如: 返回结果示例:
是\u premium=0&hotlink\u traffic\u kb=70
,但它不起作用不是有用的错误消息。你期望得到什么样的结果,你得到了什么?