我有一个计划在制作自动登录服务后进行 android web 解析......但我有一个问题......我尝试解析到http://communion.gntc.net/我看到 www.w3.org/xhtml .. .xhtml...如何制作自动登录服务...只是我知道使用'post方法'登录
源尝试该 url 连接并尝试登录,但我无法登录。只是...再次登录读取流源屏幕... main.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) {
}
}
.........
}