HttpPostTest 接口获取 重定向

来源:互联网 发布:驱蚊软件下载 编辑:程序博客网 时间:2024/06/03 08:07
public class HttpPostTest {      void testPost(String urlStr) {          try {              URL url = new URL(urlStr);              URLConnection con = url.openConnection();              con.setDoOutput(true);              con.setRequestProperty("Pragma:", "no-cache");              con.setRequestProperty("Cache-Control", "no-cache");              con.setRequestProperty("Content-Type", "text/xml");                OutputStreamWriter out = new OutputStreamWriter(con                      .getOutputStream());                  String xmlInfo = getXmlInfo();              out.write(new String(xmlInfo.getBytes("ISO-8859-1")));              out.flush();              out.close();              BufferedReader br = new BufferedReader(new InputStreamReader(con                      .getInputStream()));              String line = "";              int i=0;            for (line = br.readLine(); line != null; line = br.readLine()) {              System.out.println(i+++"条----"+line);            }          } catch (MalformedURLException e) {              e.printStackTrace();          } catch (IOException e) {              e.printStackTrace();  ;        }      }  

0 0