HttpClient(Apache)-在线登录 [英] HttpClient (Apache) - online Login
问题描述
我正在尝试登录Internet页面.我一直在做古怪的尝试,试图找到实现这一目标的正确方法.我到目前为止所得到的是:
我正在使用Apache包(HttpClient,代码,日志记录).
Hi,
I''m trying to login on an internet Page. I''ve been googeling and trying to find the right way to achieve this. What i got this far is:
I''m using the Apache package (HttpClient, Code, Logging).
import java.io.*;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.Header;
public class TestCode {
static final String loginSite = "****";
static final String checkSite = "****";
public static void main(String[] args) throws Exception{
HttpClient client = new HttpClient();
cient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
PostMethod post = new PostMethod(loginSite);
post.setRequestHeader(new Header("User-Agent", "****"));
post.addParameter("name","****");
post.addParameter("password","****");
post.addParameter("button_name","****"); //<--Press Button?
client.executeMethod(post);
BufferedReader in = new BufferedReader(
new InputStreamReader(
post.getResponseBodyAsStream()));
String decodedString;
while ((decodedString = in.readLine()) != null) {
System.out.println(decodedString);
}
in.close();
post.releaseConnection();
}
}
这是我要登录的Internet Packe:
This is the Internet Packe i''m trying to log in:
<<pre lang="xml">form method="post" name="post_name" action="TMP.php">
<table cellpadding="1" cellspacing="1" id="login_form">
<tbody>
<tr class="top">
<th>Enter Name:</th>
<td>
<input class="text" type="text" name="name" value="Login_Name_Here" /> <span class="error"> </span>
</td>
</tr>
<tr class="btm">
<th>Enter Password:</th>
<td>
<input class="text" type="password" name="password" value=""
maxlength="20" /> <span class="error"> </span>
</td>
</tr>
</tbody>
</table>
<p class="btn">
<input type="image" value="login" name="button_name" onclick="xy();" id="btn_login" class="dynamic_img" src="img/x.gif" alt="Login-Button" />
<input type="hidden" name="w" value="" />
<input type="hidden" name="login" value="99999999" />
</p>
</form>
在回应中,我输入了密码&名称已填写.
我不确定是否必须按下"按钮.
同样,我们仍然在登录页面上得到响应(名称和密码ist过滤在值"下).
通常,当我在浏览器中登录时,i-net页面会将我发送到其他页面
(只需更改页面:TMP.php).
有人有线索吗?
提前谢谢.
-------------------------------------------------- --------------
好,又是我,
现在,我正在尝试一个更简单的示例.没有登录!
但是我还是不懂PostMethod ...
什么有效我了解的是GetMethod:
http://hc.apache.org/httpclient-3.x/tutorial.html
->我获得了互联网页面的信息.
但是PostMethod仍然不起作用:
http://hc.apache.org/httpclient-3.x/methods/post.html
->在这里,我得到了相同的信息(例如与GetMethod一样)
有没有人在现有的互联网页面上运行PostMethod示例?
感谢您提供任何帮助
In the response i get, the password & name is fild in.
I''m not sure if i have to "press" the Button or not.
Also wenn i get the response i''m still on the login page (name & password ist fild in the under "value").
Usually when i login on my browser the i-net page sends me to an other page
(Just changed the page: TMP.php).
Anyone has a clue?
Thanks in advance.
----------------------------------------------------------------
Ok, it''s me again,
right now i''m trying on an easier example. No login!
But still i don''t get the PostMethod...
What works & and what i understand is the GetMethod:
http://hc.apache.org/httpclient-3.x/tutorial.html
-> I get the information of the internet page.
But what doesn''t work still is the PostMethod:
http://hc.apache.org/httpclient-3.x/methods/post.html
-> Here I get the same information (like with GetMethod)
Has anybody a working PostMethod example on an excisting internet page??
Any help is appreciated
推荐答案
请详细说明问题所在吗?
please elaborate your problem where it is ?
这篇关于HttpClient(Apache)-在线登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!