how to interact with cookie android?
I am having webview("http://m.platt.com/Login.aspx"),which contains three text fields like acc num,username and password.Now i need to interact with cookies, means i need to store that text fields.After that i need to post that url then it sholud be login status.I don't how to do this.Please can you help me? sorry for my bad english. my source code is here:
private boolean login(String loginurl){
String _URL = loginurl;
String BOUNDARY = "----------------------------tjays";
Log.v("send reply url",""+loginurl);
// "----MultiPartBoundary";
try {
URL url = new URL(_URL);
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + BOUNDARY);
conn.connect();
DataOutputStream dos = new DataOutputStream(
conn.getOutputStream());
dos.writeBytes("\r\n--"
+ BOUNDARY
+ "\r\nContent-Disposition: form-data; name=\"body\";\r\n\r\n"
+ mEditAccountNumber.getText().toString()+mEdit_userName.getText().toString()+mEdit_password.getText().toString());
dos.writeBytes("\r\n--" + BOUNDARY + "\r\n");
dos.flush();
dos.close();
// Ensure we got the HTTP 200 response code
responseCode = conn.getResponseCode();
if(responseCode == 200){
responseCode_logout=0;
Log.v("response url ", "-开发者_Python百科---------->"+dos.toString()+""+dos.size());
sign_in.setText("Sign Out");
Toast.makeText(Settings.this,"Logined ",Toast.LENGTH_SHORT).show();
sign_out = true;
}
if (responseCode != 200) {
sign_out = false;
throw new Exception(String.format(
"Received the response code %d from the URL %s",
responseCode, url));
}
conn.disconnect();
} catch (Exception e) {
// Logger.getAnonymousLogger().severe(e.getMessage());
return false;
}
return true;
}
精彩评论