我有一个Main()
类,我在其中序列化一个名为Names
. 我正在使用Apache HttpClient
'sHttpPost()
来调用servlet
.
public static void main(String[] args) {
Names names = new Names();
names.setName("ABC");
names.setPlace("Bangalore");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("Name.txt"));
out.writeObject(names);
out.close();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost:6080/HttpClientGson/FirstHttpPostServlet");
现在,我如何发送ObjectOutputStream
对象?我写了以下行
httppost.setEntity(out)
但setEntity()
只能取对象HttpEntity
类型。有没有其他方法HttpClient
可以用来发送序列化对象?