我有一个客户端服务器应用程序,在我的Serializable
两面都有一个类。我必须使用ObjectOutputStream
从编写该类的对象,client
并ObjectInputStream
在服务器上使用读取它。
在客户端上,我正在使用Apache HttpClient
(4.2版)。我必须在HttpPost
请求中发送可序列化的对象。如何以HttpPost
一种可以ObjectInputStream
在服务器上读取的方式将对象写入请求?
我正在发送这样的请求:
httpClient.execute(host,postRequest);
您需要使用BasicHttpEntityEnclosingRequest
包含的SerializableEntity
。
基本上,它看起来像这样:
BasicHttpEntityEnclosingRequest postRequest = new BasicHttpEntityEnclosingRequest("POST", "uri");
postRequest.setEntity(new SerializableEntity(yourObject, false));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句