如何取得HttpClient的输出流,然后向这个输出流上写东西。

解决方案 »

  1.   

     
        String strResult = "";
        InputStream inStream = null;
        PrintWriter out = null;
        URL httpurl = new URL(myURL);
         
          HttpURLConnection httpConn = (HttpURLConnection) httpurl.openConnection();
          httpConn.setRequestMethod("POST");
          httpConn.setDoOutput(true);
          httpConn.setDoInput(true);      out = new PrintWriter(httpConn.getOutputStream());
        
          out.print(strMsg);
          out.flush();
          out.close();
          //Thread.sleep(2000);
          inStream = httpConn.getInputStream();
          StringBuffer strBuffer = new StringBuffer();
          while ( (nByte = inStream.read()) != -1) {
            strBuffer.append( (char) nByte);
          }
          strResult = strBuffer.toString();
          inStream.close();
      

  2.   

    谢谢大家,我是说使用HttpClient这个东西来实现。后来我在网上找了一下,HttpClient是不支持写输出流的。