数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

使用request.getInputStream() 获取POST数据


发布日期:2019年11月26日
 
使用request.getInputStream() 获取POST数据

近有个项目下需要接收POST过来的XML数据包在struts中的Action方法中调用requestgetInputStream() 发现无法读到任何数据 以下是POST数据的程序代码: Java代码

URL url = new URL(urlBuf);

HttpURLConnection httpURLConnection = (HttpURLConnection) url

openConnection();

(true);

(true);

(POST); ();

();

();

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(

() GBK));

outwrite(word);

outflush();

view plaincopy to clipboardprint?

URL url = new URL(urlBuf);

HttpURLConnection httpURLConnection = (HttpURLConnection) url

openConnection();

(true);

(true);

(POST); ();

();

();

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(

() GBK));

outwrite(word);

outflush();

URL url = new URL(urlBuf);

HttpURLConnection httpURLConnection = (HttpURLConnection) url

openConnection();

(true);

(true);

(POST);();

();

();

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(

() GBK));

outwrite(word);

outflush();这个是读取程序代码: Java代码

BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)requestgetInputStream()));

String line = null;

StringBuilder sb = new StringBuilder();

while((line = brreadLine())!=null){

sbappend(line);

}

view plaincopy to clipboardprint?

BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)requestgetInputStream()));

String line = null;

StringBuilder sb = new StringBuilder();

while((line = brreadLine())!=null){

sbappend(line);

}

BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)requestgetInputStream()));

String line = null;

StringBuilder sb = new StringBuilder();

while((line = brreadLine())!=null){

sbappend(line);

}开始还以为是犯了什么低级错误不断调试查找原因无果baidu上搜索了下众说纷纭也没有很好的解决方案我也左思右想文件上传也是在Action立面处理的组件肯定用到inpputStream一点问题没有没可能这里不行后来灵光一闪在POST程序中加入: Java代码

(contenttype text/html);

view plaincopy to clipboardprint?

(contenttype text/html);

(contenttype text/html);测试成功! 根据以上现象我们不难看出struts对没有指定contenttype的request请求封装时候作了一些处理导致无法在Action中获取requestgetInputStream() 和 requestgetReader()

上一篇:数据库驱动程序测试的建议

下一篇:JXTA下的媒体数据传输