如何将请求发送到已登录站点的其他页面

| 首先,我要连接到该站点。 之后,我想通过此连接从其他页面获取数据 样品: 1-通过用户密码连接到http://site.com/Login 2-从http://site.com/Secret获取机密数据 我该怎么做,请帮我...
OutputStreamWriter request = null;
    url = new URL(\"http://site.com/Login\"); 
    String response = null; 
    EditText user = (EditText)this.findViewById(R.id.user);
    EditText pass = (EditText)this.findViewById(R.id.pass);
    String parameters ;

    try {
        System.setProperty(\"http.keepAlive\", \"true\");

        url = new URL(\"http://site.com/Home/Login\"); 
        httppost = (HttpURLConnection) url.openConnection();
        httppost.setDoInput(true);
        httppost.setDoOutput(true);
        httppost.setRequestMethod(\"POST\");
        httppost.setRequestProperty(\"User-Agent\", \"Mozilla/5.0 Linux U Android 2.3.3 tr-tr HTC_DesireHD_A9191 Build/GRI40 AppleWebKit/533.1 KHTML, like Gecko Version/4.0 Mobile Safari/533.1\");
        httppost.setRequestProperty(\"Accept_Language\", \"en-US\");
        httppost.setRequestProperty(\"Connection\", \"Keep-Alive\"); 
        httppost.setRequestProperty(\"Content-Type\", \"application/x-www-form-urlencoded\");

        request = new OutputStreamWriter(httppost.getOutputStream());

        parameters = \"username=\"+user.getText()+\"&password=\"+pass.getText();
        request.write(parameters);
        request.flush();
        request.close(); 

        String line = \"\";               
        InputStreamReader isr = new InputStreamReader(httppost.getInputStream());
        BufferedReader reader = new BufferedReader(isr);
        StringBuilder sb = new StringBuilder();
        while ((line = reader.readLine()) != null)
        {
            sb.append(line + \"\\n\");
        }
        response = sb.toString();

        Toast.makeText(this,response, Toast.LENGTH_LONG).show();             

        isr.close();
        reader.close();

    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
    }
已邀请:
您应该使用WebView,但是抱歉,您无法获取Webview内容。 如果您拥有服务器端代码,并且想从Java访问,则应该使用访问令牌进行更安全的连接,并使用JSON或XML获取数据。或者,还有一种更安全的连接类型是OAuth2。 如果您不拥有服务器,则应在webview中显示http://site.com/Login网址。当用户登录时,您的Web视图中将包含cookie。您可以使用CookieManager http://developer.android.com/reference/android/webkit/CookieManager.html并使用此Cookie发送数据并获取结果。这种方法并不容易,并且可以根据服务器端实现来区分。

要回复问题请先登录注册