HTTP Post登录不起作用

时间:2015-12-02 17:46:14

标签: java android http post httpurlconnection

我试图检查一侧http://ipool.ba-berlin.de/main.php的密码是否有效。通常是站点响应代码302,并重定向回登录页面或主站点。

但即使用正确的密码尝试代码,"位置"响应标题指向登录页面。

有什么建议吗?

protected Void doInBackground(Void... params) {
    try {
        URL url = new URL("http://ipool.ba-berlin.de/main.php" + "?" +String.format("action=%s",URLEncoder.encode("login","UTF-8")));
        HashMap<String, String> postDataParams = new HashMap<>();
        postDataParams.put("FORM_LOGIN_PAGE","home");
        postDataParams.put("FORM_LOGIN_REDIRECTION","");
        postDataParams.put("FORM_LOGIN_NAME","student");
        postDataParams.put("FORM_LOGIN_PASS","supersecretpassword");
        postDataParams.put("FORM_ACCEPT","1");
        postDataParams.put("LOGIN","login");
        postDataParams.put("login","Einloggen");

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection.setUseCaches(false);
        connection.setReadTimeout(15000);
        connection.setConnectTimeout(15000);
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setInstanceFollowRedirects(false);

        OutputStream os = connection.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
        Log.d("post", getPostDataString(postDataParams));
        writer.write(getPostDataString(postDataParams));
        writer.flush();
        writer.close();

        Log.e("loc",connection.getHeaderField(URLEncoder.encode("Location", "UTF-8")));


    } catch (Exception e) {
        Log.e("ex", e.getMessage() + "");
    }

我试图重述谷歌浏览器的请求,如下所示。

General
Remote Address:194.94.23.19:80
Request URL:http://ipool.ba-berlin.de/main.php?action=login
Request Method:POST
Status Code:302 Moved Temporarily

Response Headers
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:keep-alive
Content-Length:0
Content-Type:text/html
Date:Wed, 02 Dec 2015 17:48:22 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Location:http://ipool.ba-berlin.de/main.php
Pragma:no-cache
Server:Apache/2.2.3 (Linux/SUSE)
X-Powered-By:PHP/5.2.0

Request Headers
   Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,de;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Content-Length:133
Content-Type:application/x-www-form-urlencoded
Cookie:PHPSESSID=hfhs6ms3m5kp0bv7ihkkadbb70s10kvo
Host:ipool.ba-berlin.de
Origin:http://ipool.ba-berlin.de
Pragma:no-cache
Referer:http://ipool.ba-berlin.de/index.php?next=&m=0
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36

Query String Parameters
action:login

Form Data
FORM_LOGIN_PAGE:home
FORM_LOGIN_REDIRECTION:
FORM_LOGIN_NAME:student
FORM_LOGIN_PASS:putsupersecretpasswordinhere
FORM_ACCEPT:1
LOGIN:login
login:Einloggen

0 个答案:

没有答案