开发者

Android django communication

In the below i am sending a request to a server where Applications are handled by django .My question is that from django how to send a response back to Android client..

django code:

def mylogin(request):
    // return HttpResponse or render_to_response ....

This is my android code

  package senddata.com;

  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.util.EntityUtils;
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.Toast;

  public class SenddataActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button btn=(Button) fi开发者_运维百科ndViewById(R.id.button1);
    btn.setOnClickListener(new OnClickListener() {


        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(), "data sent", Toast.LENGTH_LONG).show();
             try
                {
                 Toast.makeText(getApplicationContext(), "data sent1", Toast.LENGTH_LONG).show();
                HttpClient client = new HttpClient();
                String postURL="http://192.171.254.61/mylogin/";
                HttpPost post = new HttpPost(postURL);
                MultipartEntity reqEntity = new MultipartEntity();
                             //send data

                        HttpEntity resEntity = response.getEntity();  
                if (resEntity != null) {    
                    String r = EntityUtils.toString(resEntity);
                    if(r.startsWith("success")) {
                    Toast.makeText(getApplicationContext(), "data sent", Toast.LENGTH_LONG).show();
                    }               
                    }
                }
                catch(Exception e)
                {
                    Toast.makeText(getApplicationContext(), "data not sent" + e, Toast.LENGTH_LONG).show();
                }


        }
    });

      }
  } 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜