-1

我是 android 的初学者,并为用户输入登录详细信息的应用程序设计了登录 GUI。在 Java 代码(字符串)中获取登录详细信息后,如何将其传递给服务器以检查有效组合?此外,当新用户输入注册详细信息时,我如何将其传递到服务器并将其存储在 DB(MySQL DB)中?网络服务的目的是什么?我应该使用 Web 服务还是 servlet(这不是唯一的事情,稍后在我的应用程序中我需要向/从服务器发送联系方式)?

我学习了 SOAP 网络服务。请指导我如何在 android 中开发此应用程序。

4

2 回答 2

0

在这篇文章中查看我的回答使用 HttpURLConnection 添加对 POST 的调用主体

这将帮助您连接到 Web 服务并将数据传递给该服务

于 2012-07-05T09:28:47.117 回答
-1

(通过使用 eclipse)试试这个我做了一个研究,发现这个

public class AndroidtestingActivity extends ListActivity  {

    /** Called when the activity is first created. */
    @Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    String result = null;
    InputStream is = null;
    StringBuilder sb = null;
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    List<String> r = new ArrayList<String>();

    try{

    //http post
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("YOUR SITE");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    is = entity.getContent();
    }
    catch(Exception e){
        Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
   }

    //Convert response to string  
    try
    {
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));

      sb = new StringBuilder();

      String line = null;

      while ((line = reader.readLine()) != null) 
      {
         sb.append(line + "\n");
      }

      is.close();

      result = sb.toString();
    }
    catch(Exception e)
    {
        Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
    }
    //END Convert response to string   
    try{
            JSONArray jArray = new JSONArray(result);
            JSONObject json_data=null;
            for(int i=0;i<jArray.length();i++)
            {
               json_data = jArray.getJSONObject(i);                   
               r.add(json_data.getString("name")+json_data.getString("id"));
           }
           setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, r));
        }
        catch(JSONException e1){
            Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
        } catch (ParseException e1) {
            Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
    }

}

public boolean onCreateOptionsMenu(android.view.Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);
    MenuInflater blowUp = getMenuInflater();
    blowUp.inflate(R.menu.cool_menu, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch(item.getItemId()){
    case R.id.iadd:
        Intent i = new Intent("android.intent.action.ADD");
        startActivity(i);

        break;  
    }
    return false;
}
}

必须使用 PHP Android - PHP - server/database 将 Android 连接到服务器

于 2012-07-05T07:09:27.290 回答