如何在Android和GAE-python之间发送和接收数据

时间:2011-07-05 14:13:06

标签: java android python django google-app-engine

我正在使用此代码将数据发送到部署了我的gae-python应用程序的网站。但我不知道如何在另一端接收它。

protected void tryLogin(String mUsername, String mPassword)
    {           
        HttpURLConnection connection;
       OutputStreamWriter requestself = null;

            URL url = null;   
            String response = null;         
         String parameters = "username="+mUsername+"&password="+mPassword;   

            try

            {
                url = new URL("http://www.pranshutrial3.appspot.com");
                connection = (HttpURLConnection) url.openConnection();
                connection.setDoOutput(true);
                connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                connection.setRequestMethod("POST");    

                requestself = new OutputStreamWriter(connection.getOutputStream());
                requestself.write(parameters);
                requestself.flush();
                requestself.close();            
                String line = "";               
                InputStreamReader isr = new InputStreamReader(connection.getInputStream());
                BufferedReader reader = new BufferedReader(isr);
                StringBuilder sb = new StringBuilder();
                while ((line = reader.readLine()) != null)
                {
                    sb.append(line + "\n");
                }
                // Response from server after login process will be stored in response variable.                
                response = sb.toString();
                // You can perform UI operations here
                Toast.makeText(this,"Message from Server: \n"+ response, Toast.LENGTH_LONG).show();             
                isr.close();
                reader.close();

            }
            catch(IOException e)
            {
                // Error
            }


    }

0 个答案:

没有答案