簡體   English   中英

如何將序列化的 object 從 Android 客戶端發送到 Google App Engine Servlet?

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

我如何將序列化的 object 從 Android 客戶端發送到 Google App Engine Servlet。
我有這個代碼:

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( ????
}

我如何從這里繼續?
有沒有更好的辦法?

給你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));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM