解决方案 »

  1.   

    远程数据库可以是各种形式啊这和android没关系,就直接用httpclient或者socket传数据就OK了
      

  2.   

    不太理解,能否举个例子呢?
    httpclient的实现流程?
    socket的实现流程?我就是不太理解怎么实现服务器和Android的数据交互。我也不知道服务器应该用什么,能给一个推荐吗?就是简单的存储用户的账号信息。
      

  3.   

    你设计2个WEB页面,一个页面有账号和密码输入框,提交的时候跳到第二个页面显示出来或者数据插入到数据库,成功后第二个页面就可以算作webservice接口了,手机上只要模拟第一个页面输入账号密码跳转到第二个页面即可。
    手机一点点你得按你的要求改改,主要使用httpclient httprespone
        public static String uploadSubmit(String url, Map<String, String> param,
                                          File file) throws Exception {
            HttpPost post = new HttpPost(url);        MultipartEntity entity = new MultipartEntity();
            if (param != null && !param.isEmpty()) {
                for (Map.Entry<String, String> entry : param.entrySet()) {
                    if (entry.getValue() != null
                            && entry.getValue().trim().length() > 0) {
                        entity.addPart(entry.getKey(),
                                new StringBody(entry.getValue()));
                    }
                }
            }
            // 添加文件参数
            if (file != null && file.exists()) {
                entity.addPart("file", new FileBody(file));
            }
            post.setEntity(entity);
            HttpClient httpClient=new DefaultHttpClient();
            HttpResponse response = httpClient.execute(post);
            //String serverResponse = EntityUtils.toString(response.getEntity()); 这样可以直接获得,但是下面的代码可以获得复杂的数据
            int stateCode = response.getStatusLine().getStatusCode();
            StringBuffer sb = new StringBuffer();
            if (stateCode == HttpStatus.SC_OK) {
                HttpEntity result = response.getEntity();
                if (result != null) {
                    InputStream is = result.getContent();
                    BufferedReader br = new BufferedReader(
                            new InputStreamReader(is));
                    String tempLine;
                    while ((tempLine = br.readLine()) != null) {
                        sb.append(tempLine);
                    }
                }
            }
            post.abort();
            return sb.toString();
        }
      

  4.   


    public String post(String url,Map<String,String> parameter) throws Exception{
    Log.i(Constants.LOG_TAG, url);

    List<BasicNameValuePair> params = new LinkedList<BasicNameValuePair>();  
    for(String key : parameter.keySet()){
    params.add(new BasicNameValuePair(key, parameter.get(key)));
     Log.i(Constants.LOG_TAG, key + "-->" + parameter.get(key));
    }
    String result = "";
    HttpPost postMethod = new HttpPost(url);  
    postMethod.setHeader("Cookie", cookieString);
    postMethod.setEntity(new UrlEncodedFormEntity(params, "utf-8"));

    HttpClient httpClient = new DefaultHttpClient();  

    HttpResponse response = httpClient.execute(postMethod); //Send POST Request
    Log.i(Constants.LOG_TAG, "http : "+String.valueOf(response.getStatusLine().getStatusCode()));
    if(200==response.getStatusLine().getStatusCode()){
    result = EntityUtils.toString(response.getEntity(), "utf-8");
    }

    return result;
    }