綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 登入→連結→連結→撈到資料

[複製連結] 查看: 1326|回覆: 3|好評: 0
跳轉到指定樓層
樓主
劉兆峰 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2012-10-12 19:02

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
import java.net.*;
import java.io.*;
import java.sql.*;


public class Main{

        public static void main(String[] aaa) throws Exception{
                AccessJDBCTest ADB = new AccessJDBCTest();
                String allmsg="";
  
                HttpURLConnection urlConnection= null;//定義一個HTTP連線
                URL url=new URL("http://sis.hust.edu.tw/face/login/login0.asp?sis_login=帳號&pwd=密碼liketeaboy");//定義一串URL
                urlConnection=(HttpURLConnection)url.openConnection();//將URL餵給HttpURLConnection
                urlConnection.setRequestMethod("GET");//設定參數傳遞方式(GET or POST)
                urlConnection.setDoOutput(true);
                urlConnection.setDoInput(true);
                urlConnection.connect();//開啟連線
                InputStream yahooHTML=urlConnection.getInputStream();//將yahoo的網頁內容儲存下來
                BufferedReader br = new BufferedReader(new InputStreamReader(yahooHTML));

                String str = "";
                String strID="";
                String p1="",p2="",p3="";
                int count =9;
                while((str = br.readLine()) != null){
                        //System.out.print(str);
                        allmsg += str;

                        int Loc = str.indexOf("input");
                        if (Loc != -1){
                            count++;
                            if ((Loc = str.indexOf("name",Loc+1)) != -1){
                               if ((Loc = str.indexOf("\"",Loc+1)) != -1){
                                  strID = str.substring(Loc+1,Loc+3);
                                  if (strID.equals("id")){
                                      //把id的value抓出來
                                      p2 = "kkk";
                                  }else if(strID.equals("pw")){
                                      //把pwd的value抓出來
                                      p3 = "666";
                                  }
                               }
                            }
                        }
                }
                ADB.insertTable(p1+count,p2,p3);
                br.close();
        }
}




這個是java撈資料程式....
其實我是想問各位大大,要怎麼用寫好的撈資料程式從登入驗證帳密→超連結→超連結→超連接→到要撈的資料

<html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=big5"></head>      <body>                             <form name="form3" method="post">                               <input type="hidden" name="id" value="-1">                <input type="hidden" name="pwd" value="1wEWKwrCP83reK7KcQyql3XhOLkd228Rid9mLgZb+9EGNQYPZ1dFxF1VcbSD9q7e">               <input type="hidden" name="submit1" value="login">                                                                    </form>                        <script>                                                                            document.form3.action="http://sis.hust.edu.tw/face/login/login2.asp";                                                    document.form3.submit();                                                </script>     </body></html>
Process completed.
這是我用撈資料程式撈系統登入的地方的訊息
但是我不知道怎麼利用解析好的ID、PW的value來進行驗證,然後呼叫下個點選的超連結按鈕....
如果知道的大大請給我個解決答案....小弟會非常感謝你的.....
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
ploglin | 收聽TA | 只看該作者
發表於 2012-10-15 09:32
你的問題是 Android? 還是 JSP?
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

板凳
sheep999 | 收聽TA | 只看該作者
發表於 2012-10-23 10:57
GET:

                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet
                ("http://127.0.0.1/test.php?user=kevin&passwd=13579"); // URL
                        HttpResponse res = client.execute(get);//送出
                        HttpEntity entity = response.getEntity();
                        InputStream in = entity.getContent();//取出 回傳值
                        int temp;
                        while ( (temp = in.read()) !=-1){
                                info.append("" + (char)temp); //印出 data
                        }
                       
                        in.close();


POST:
        HttpClient client = new DefaultHttpClient();           
            HttpPost post = new HttpPost("http://127.0.0.1/test2.php");
           
            StringBody userId = new StringBody("userId");
            StringBody passwd = new StringBody("1234");
            MultipartEntity entity = new MultipartEntity();
            entity.addPart("user", userId);  //第一個參數 REQUEST的變數名 第二個是 value
            entity.addPart("passwd", passwd);
  
           
            post.setEntity(entity);
                HttpResponse response = client.execute(post); //送出
                HttpEntity res_entity = response.getEntity();
                InputStream in = res_entity.getContent();//取出 回傳值
                int temp;
                while ( (temp = in.read()) !=-1){
                        info.append("" + (char)temp);
                }
               
                in.close();
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

地板
sheep999 | 收聽TA | 只看該作者
發表於 2012-10-23 11:02
POST:
HttpClient client = new DefaultHttpClient();           
            HttpPost post = new HttpPost("Http://127.0.0.1/test.php");
           
            StringBody userId = new StringBody("root");
            StringBody passwd = new StringBody("1234");
            MultipartEntity entity = new MultipartEntity();
            entity.addPart("user", userId); // (Request變數,value)
            entity.addPart("passwd", passwd);

           
            post.setEntity(entity);
                HttpResponse response = client.execute(post); //送出
                HttpEntity res_entity = response.getEntity();
                InputStream in = res_entity.getContent(); //取出 回傳值
                int temp;
                while ( (temp = in.read()) !=-1){
                        info.append("" + (char)temp);
                }
               
                in.close();
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則