简体   繁体   中英

How to send serialized object from Android Client to Google App Engine Servlet?

How can i send serialized object from Android Client to Google App Engine Servlet.
i have this code:

private static HttpClient getHttpClient() 
{
if (mHttpClient == null) 
{
    mHttpClient = new DefaultHttpClient();
    final HttpParams params = mHttpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
    ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
}
return mHttpClient;
}

public static String executeHttpPost(String url, Object obj) throws Exception
{    
  HttpClient client = getHttpClient();
  HttpPost request = new HttpPost(url);
  request.set( ????
}

how do i continue from here?
is there a better way?

Here you go:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);   
out.writeObject(obj);
byte[] yourObjectSerialized = bos.toByteArray();

HttpClient client = getHttpClient();
HttpPost request = new HttpPost(url);
request.setEntity(new ByteArrayEntity(yourObjectSerialized));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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