Android登录网页

时间:2013-01-12 00:33:22

标签: android http login web

我想登录网站并从中读取数据,但我的代码无效

这是我要登录的网站的html的一部分。要登录,您必须写卡号并单击“Nastavak”按钮

<span id="rightframe_Label1" class="smalltextcell" style="display:inline-block;width:50px;">Kartica:</span>
<input name="ctl00$rightframe$TextBox1" type="text" value="601983" maxlength="19" id="rightframe_TextBox1" title="Upisati broj kartice">
<input type="submit" name="ctl00$rightframe$ProvjeraSaldoButton" value="Nastavak" id="rightframe_ProvjeraSaldoButton">

这是代码

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("webpage");

            try {
                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("rightframe_TextBox1", "numberOfCard"));
                nameValuePairs.add(new BasicNameValuePair("rightframe_ProvjeraSaldoButton", "Nastavak"));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);

                String html = inputStreamToString(response.getEntity().getContent()).toString();
                Log.e(Constants.TAG, html);


            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }   
    }

    private StringBuilder inputStreamToString(InputStream is) throws IOException {
        String line = "";
        StringBuilder total = new StringBuilder();

        // Wrap a BufferedReader around the InputStream
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));

        // Read response until the end
        while ((line = rd.readLine()) != null) { 
            total.append(line); 
        }

        // Return full string
        return total;
        }

该代码仅从登录屏幕打印出html,但登录时屏幕上没有html。我不知道问题出在哪里

0 个答案:

没有答案
相关问题