HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(uri);
String receiveMsg = null;
// 填入各个表单域的值
NameValuePair[] data = new NameValuePair[parameter0.length];
// 将表单的值放入postMethod中
for(int i=0;i<data.length;i++){
data[i] = new NameValuePair(parameter0[i], parameter1[i]);
}
postMethod.setRequestBody(data);
// 执行postMethod
try {
int statusCode = httpClient.executeMethod(postMethod);
// HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发 301或者302
if(statusCode == HttpStatus.SC_MOVED_PERMANENTLY||statusCode == HttpStatus.SC_MOVED_TEMPORARILY);
byte[] receiveData = postMethod.getResponseBody();
receiveMsg = new String(receiveData);
postMethod.releaseConnection();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
postMethod.releaseConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
postMethod.releaseConnection();
}
postMethod.getResponseBody();我servlet中用什么形式发送这样的数据才能使其接到数据
或者JSP,还是使用框架,请高手指点~~~
解决方案 »
- Http Status 500错误
- struts-tags problem
- 数据库连接问题
- Flex项目 jar not loaded. See Servlet Spec 2.3, section 9.7.2. O
- hibernate怎么读oracle中clob的值
- 在myeclipse下面开发Hibernate+Struts的问题?
- Tomcat服务器不解释jsp代码是怎么回事啊?
- 关于habernate的查询问题
- JSTL有人用过吗?
- 请教:Weblogic启动后能不能有方法关掉那个DOS窗口??
- 懂axis2 webService的同志请进来
- 请问Spring高手,BeanFacroty的结构是怎样的?
这不是用postMethod.getResponseBody()接收服务端返回的信息吗???
我想问的是服务端用什么形式返回信息和这个方式对应上!
我试了dos.write(byte[]);
dos.writeUTF();
都接不到...
比如说
dataoutputstream dos = ...
dos.writeUTF("msg");
那我们接不是
dis.readUTF();么?
就这样...
也可以用post.getResponseBodyAsString()获取文本内容
out.print(...);
out.print(...);
...
out.print(...);
out.close();
开始没有想到~~~
byte[] buffer = new byte[1024];
//buffer 中是你要发送的数据
outputStreamClientResponse.write(buffer);
String arg0 = "";//你要发送的数据
httpServletResponse.getWriter().write(arg0)