我需要通过 http post 发送大写的标头。故事的第一部分在这里描述。现在它的套接字时间。:)
Socket s = new Socket(InetAddress.getByName("localhost"), 8080);
PrintWriter pw = new PrintWriter(s.getOutputStream());
// PrintStream pw = System.out;
pw.println("POST /test-servlet/TestServlet HTTP/1.0");
String params = "key1=value1&key2=value2";
pw.println("accept = text/xml");
pw.println("accept-language: ru");
pw.println("SOAPAction: requestCreditBureau");
pw.println("eif: 3");
pw.println("host: localhost");
pw.println("content-length: " + params.getBytes().length);
pw.println();
pw.println(params);
pw.println();
pw.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String t;
while((t = br.readLine()) != null) System.out.println(t);
br.close();
这里有两个问题。
- 它不起作用。:) 服务器的 servlet 接收:
工作流 = TSM \soapaction = requestCreditBureau eif = 3
- 服务器上的 HttpServletRequest 中没有参数,只有标头。