package com.nxt.portal.framework.controller.action.subscribe;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
public class ERPXml {
public String getXml(String url,List list) throws Exception{
URL urls = new URL(url);
URLConnection rulConnection = urls.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection;
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setDoInput(true);
httpUrlConnection.setUseCaches(false);
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.setRequestProperty("accept", "*/*");
//传输字符串
/*String param="username="+java.net.URLEncoder.encode(employeeId);
System.out.println(param);
OutputStreamWriter outStrm = new OutputStreamWriter (httpUrlConnection.getOutputStream(),"UTF-8");
outStrm.flush();
outStrm.write(param);
outStrm.close();*/
//传输对象,开始写入数据
ObjectOutputStream oos = new ObjectOutputStream(httpUrlConnection.getOutputStream());
oos.writeObject(list);
oos.flush();//这句一定要写
oos.close();
InputStream inStrm = httpUrlConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inStrm));
String read = "";
StringBuffer strLine=new StringBuffer();
while ((read = br.readLine()) != null) {
strLine.append(read);
}
br.close();
inStrm.close();
httpUrlConnection.disconnect();
return strLine.toString();
}
public static void main(String[] args) throws Exception{
List list = new ArrayList();
list.add(list);
String employeeid ="LiGuo";
//另一个类的一个servlet
String url="
http://localhost:8080/wc/PostManager "; ERPXml erp=new ERPXml(); System.out.println(erp.getXml(url,list)); } //客户端,这边需要说明,传输过来的list对象里面装的是什么对象,或者list的结构是什么样的! /*public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { ObjectInputStream ois = new ObjectInputStream(request.getInputStream());//request.getInputStream() List list = null; try { Object obj = ois.readObject(); if(obj!=null){ list = (List)obj; System.err.println(obj); } } catch (ClassNotFoundException e) { e.printStackTrace(); } System.err.println(list); //String uname = request.getParameter("username"); //System.err.println("uname=/t"+uname); PrintWriter pw = response.getWriter(); pw.write("OK"); }*/ }