java android 访问DELPHI 的DATASNAP

最新版的DELPHI开发DATASNAP非常简单便捷,DataSnap的REST风格和对JSON的支持,使之成为服务器端开发的神器。

一、DATASNAP服务器中的方法:

    TServerMethods1 = class(TDSServerModule)
    Dspwire: TDataSetProvider;
    ADOQuery1: TADOQuery;
  private
    { Private declarations }
  public
    { Public declarations }
    function Askname(Sid:String):string;    //根据会员编号查姓名

    ....

二、JAVA安卓作为客户端

     final String cstr=new String("http://192.168.1.123:8080/datasnap/rest/TServerMethods1/Askname");

     final EditText et=(EditText)findViewById(R.id.editText1);
     final TextView tv=(TextView)findViewById(R.id.textView1);
  
     Button bt1=(Button)findViewById(R.id.button1);
     bt1.setOnClickListener(new OnClickListener(){
         @Override
         public void onClick(View arg0) {
    // TODO Auto-generated method stub
    HttpClient client=new DefaultHttpClient();
    HttpGet httpGet=new HttpGet(cstr+"/"+et.getText().toString());
   
    HttpResponse response = null;
    response = client.execute(httpGet);
    inputStream inputStream=null;
    inputStream=response.getEntity().getContent();
    StringBuffer buffer = new StringBuffer();  
    BufferedReader bufferReader = new BufferedReader( new InputStreamReader(inputStream));  
    String str = new String("");  
    while ((str = bufferReader.readLine()) != null) { 
                       buffer.append(str)  };
      bufferReader.close();
    tv.setText(buffer.toString());

    }}

   剩下的就是解析JSON了。

  三、用DELPHI 做android 客户端的话,访问DATASNAP就非常简单了...

 

 

你可能感兴趣的:(android)