如何与cookie android进行交互?

时间:2011-06-02 14:25:21

标签: android

我正在使用webview(“http://m.platt.com/Login.aspx”),其中包含三个文本字段,如acc num,username和password.Now我需要与cookie进行交互,这意味着我需要存储该文本字段。之后,我需要发布该网址然后它sholud是登录状态。我不知道怎么做。请你帮我吗?对不起,我的英语不好。 我的源代码在这里:

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 ", "----------->"+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;
    }

0 个答案:

没有答案