java - Android如何解析XHTML

标签 java android parsing xhtml android-parser

我有一个计划在创建自动登录服务后进行android web解析... 但我有一个问题... 我尝试解析http://communion.gntc.net/我看到 www.w3.org/xhtml... xhtml...如何进行自动登录服务...只是我知道使用“post方法”登录

<小时/>

Image[Click]

源尝试该网址连接并尝试登录,但我无法登录。只是...再次登录读取流源屏幕... ma​​in.java(部分)

public class Main extends SherlockActivity {
   ........

    public class async_Login extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {
            try {
                // URL setting
                communion_Url = new URL("http://communion.gntc.net/Default.aspx");
                connection = (HttpURLConnection) communion_Url .openConnection();

                // <Form> setting
                connection.setRequestProperty("content-type", "application/x-www-form-urlencoded");

                // method choose
                connection.setRequestMethod("POST");

                // transfer mode
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.setUseCaches(false);
                connection.setDefaultUseCaches(false);

                // server input info
                StringBuffer buffer = new StringBuffer();
                buffer.append("__VIEWSTATE").append("=").append("%2FwEPDwUKLTIyMDExNjMxNA9kFgICAw9kFgICAw9kFgICBw9kFgICAQ9kFgICCQ8QZGQWAGQYAgUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFFExvZ2luVmlldzEkaWJ0bkxvZ2luBRZMb2dpblZpZXcxJG12TG9naW5WaWV3Dw9kZmQyduUiycnsslmd80DsHFWnE%2F5ewQ%3D%3D").append("&");
                buffer.append("__EVENTVALIDATION").append("=").append("%2FwEWBAK%2F9LzRAwK73JjWBAKVqtrbDwLeooalDbXptfMUzAby%2FyAzoqPXkmhJ%2Bq6x").append("&");
                buffer.append("LoginView1%24txtID").append("=").append(params[0]).append("&"); //ID values
                buffer.append("LoginView1%24ibtnLogin.x").append("=").append("1").append("&");
                buffer.append("LoginView1%24ibtnLogin.y").append("=").append("1").append("&");
                buffer.append("LoginView1%24txtPW").append("=").append(params[1]); // PS values
                fileSave(buffer.toString());
                OutputStream opstrm = new     BufferedOutputStream(connection.getOutputStream());
                opstrm.write(buffer.toString().getBytes());
                opstrm.flush(); 
                opstrm.close();

                connection.setRequestMethod("GET");
                InputStream is = connection.getInputStream();
                BufferedReader rd = new BufferedReader(new InputStreamReader(is));
                String line;
                StringBuffer response = new StringBuffer(); 
                while((line = rd.readLine()) != null) {
                    response.append(line);
                    response.append('\r');
                }
                rd.close();

                //fileSave(response.toString());
                Log.i("#async_Login#", response.toString());
            } catch (IOException e) {
                Log.i("##async_Login##", "Communion Connect Failure");
                //e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String result) {

        }
    }

.........
}

最佳答案

您正在使用 GET 方法:connection.setRequestMethod("GET"); 尝试将其更改为 POST。

关于java - Android如何解析XHTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16424647/

相关文章:

java - 如何用paintComponent()绘制不同的对象?

java - 警告 : Error while registering Oracle JDBC Diagnosability MBean

android - 错误 :Failed to resolve: support-vector-drawable

java - 使用 robolectric get Resources$NotFoundException 运行单元测试

java - 当音乐应用程序通知栏中的歌曲更改时,歌曲名称和专辑封面不会更改

javascript - 解析带引号的简单 json 时出现语法错误?

java - 在Java中解码SQL数据类型 "image"数据

java - 为什么我无法将现有 Eclipse 项目转换为动态 Web 项目?

c - 初学者帮助: Parsing in C

parsing - 如何从 Dart 分析器扫描仪获取评论 token ?