简体   繁体   English

如何将记录从android手机db(sqlite)上传到网页

[英]How to upload a record from android phone db(sqlite) to a web page

I want to setup an Android app which has some records in its db and user can forward a record to server database and display them in a web page 我想设置一个在数据库中有一些记录的Android应用程序,用户可以将记录转发到服务器数据库并在网页中显示它们

can any one suggest me requirements for this process 有人可以建议我此过程的要求吗

Try this 尝试这个

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
 private static final String HostUrl =" http://test.gloriatech.in:5657/Service.svc";//(your url)
 private static final String NAMESPACE = "http://tempuri.org/";
 private HttpTransportSE httpTransport = new HttpTransportSE(HostUrl);
SoapPrimitive response=null;
final String methodname="InsertGPSInformation";
    request = new SoapObject(NAMESPACE,methodname);
    envelope.dotNet = true;
    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String getImeNumber=telephonyManager.getDeviceId();
    SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String newtime =  sdfDateTime.format(new Date(System.currentTimeMillis()));
    request.addProperty("IMEINumber",getImeNumber);
    request.addProperty("Longitude",longitudeField.getText().toString()); 
    request.addProperty("Latitude",latituteField.getText().toString()); 
    request.addProperty("Date",newtime);
    request.addProperty("formName",className);
    envelope.setOutputSoapObject(request);
     String result = null;
    try
     {          
        httpTransport.call(NAMESPACE+"IService/"+methodname, envelope);
        response = ( SoapPrimitive )envelope.getResponse();
        result=response.toString();
     }
    catch(Exception e)
     {
         Toast.makeText(this, "Exception"+e.toString(), Toast.LENGTH_LONG).show();
        Log.e("Upload Picture Error:",e.getMessage());
     }
    Toast.makeText(this, ""+result, Toast.LENGTH_LONG).show();

您可以通过两种方式做到这一点,一种是使用URL连接,另一种是通过访问可用于该上传页面的网络服务。

You can either use a webservice or servlet 您可以使用Web服务或servlet

if you are using webservice then you will have to do something like 如果您使用的是网络服务,则必须执行类似的操作

SoapObject requestObject = new SoapObject(NAMESPACE, METHOD_NAME);
        requestObject.addProperty("name", value);
        requestObject.addProperty("name", value);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(requestObject);
        transportSE = new HttpTransportSE(URL1);
        transportSE.call(SOAP_ACTION, envelope);

        Object obj = (Object) envelope.getResponse();

and for servlet 对于servlet

HttpResponse response = null;
            HttpEntity httpEntity;
            InputStream responseInput;
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("*URL here*");

            try {
                entity = new UrlEncodedFormEntity(postParams);

            } catch (UnsupportedEncodingException e1) {
                e1.printStackTrace();
            }
//              entity.setContentEncoding(HTTP.UTF_8);
//               entity.setContentType("text/html");
            httppost.setEntity(entity);
            try {
                response = httpclient.execute(httppost);
                Log.v("Resonse", "Request Send successfully!!!");
                httpEntity = response.getEntity();
                Log.v("Resonse", "Response recieved successfully!!!");
                responseInput = httpEntity.getContent();
                BufferedReader br = new BufferedReader(
                        new InputStreamReader(responseInput));

//....and so on //....等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM