知识大全 使用request.getInputStream() 获取POST数据

Posted

篇首语:仰天大笑出门去,我辈岂是蓬蒿人。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 使用request.getInputStream() 获取POST数据相关的知识,希望对你有一定的参考价值。

使用request.getInputStream() 获取POST数据  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  近有个项目下需要接收POST过来的XML数据包 在struts中的Action方法中 调用request getInputStream() 发现无法读到任何数据 以下是POST数据的程序代码: Java代码    URL url = new URL(urlBuf);            HttpURLConnection URLConnection = (HttpURLConnection) url                    openConnection();            (true);            (true);            ( POST );         ( );            ( );            ();            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(                    () GBK ));            out write(word);            out flush();    view plaincopy to clipboardprint?    URL url = new URL(urlBuf);            HttpURLConnection URLConnection = (HttpURLConnection) url                    openConnection();            (true);            (true);            ( POST );         ( );            ( );            ();            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(                    () GBK ));            out write(word);            out flush();

  URL url = new URL(urlBuf);      HttpURLConnection URLConnection = (HttpURLConnection) url         openConnection();      (true);      (true);      ( POST );   ( );      ( );      ();      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(        () GBK ));      out write(word);      out flush();这个是读取程序代码: Java代码    BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)request getInputStream()));            String line = null;            StringBuilder sb = new StringBuilder();            while((line = br readLine())!=null)                sb append(line);                view plaincopy to clipboardprint?    BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)request getInputStream()));            String line = null;            StringBuilder sb = new StringBuilder();            while((line = br readLine())!=null)                sb append(line);           

  BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)request getInputStream()));      String line = null;      StringBuilder sb = new StringBuilder();      while((line = br readLine())!=null)       sb append(line);      开始还以为是犯了什么低级错误 不断调试查找原因 无果 baidu上搜索了下 众说纷纭 也没有很好的解决方案 我也左思右想 文件上传也是在Action立面处理的 组件肯定用到inpputStream一点问题没有 没可能这里不行 后来灵光一闪 在POST程序中加入: Java代码    ( content type text/ );    view plaincopy to clipboardprint?    ( content type text/ );

cha138/Article/program/Java/hx/201311/26268

相关参考