- package com.lkt.jdk;
-
- import java.io.BufferedInputStream;
- import java.io.BufferedReader;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
-
- public class GetHttp {
-
- public static String getWebContent()throws IOException{
-
-
- URL url=new URL("HTTP","192.168.22.209",7001,"/Request_USER_LOGIN");
-
- HttpURLConnection conn=(HttpURLConnection)url.openConnection();
-
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-Type", "application/xml");
- conn.setRequestProperty("Connection", "Keep-Alive");
-
-
- String xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?> "+
- "<HTTP_XML EventType=\"Request_USER_LOGIN\" TargetSyscode=\"\" RequestId=\"\" TransactionId=\"\">"+
- " <Item Name=\"admin\" Password=\"670b14728ad9902aecba32e22fa4f6bd\" UserIp=\"\" Port=\"\" BusinessSysCode=\"\"/>"+
- "</HTTP_XML>";
-
- conn.setRequestProperty("Content-Length",xml.length()+"");
-
- conn.setDoOutput(true);
- conn.setDoInput(true);
-
-
-
-
-
-
- DataOutputStream dos=new DataOutputStream(conn.getOutputStream());
- dos.writeBytes(xml);
- dos.flush();
- dos.close();
-
- int code=conn.getResponseCode();
- InputStream is=conn.getInputStream();
-
-
- BufferedReader bis=new BufferedReader(new InputStreamReader(is));
- StringBuffer sb=new StringBuffer();
- String temp="";
- while((temp=bis.readLine())!=null){
- sb.append(temp+"\n");
- }
- return null;
-
- }
- public static void main(String[] args)throws Exception {
- getWebContent();
- }
- }
http发送http报文
原文:http://www.cnblogs.com/zszitman/p/4565003.html