little_lazy
2009-06-12 12:02
浏览 396
已采纳

httpclient如何获取dwr的数据?

如题,最好有个简单的范例,谢谢~~

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • wanghaolovezlq 2009-06-12 12:41
    已采纳

    你把dwr官方包里的dwr.war跑在tomcat下

    然后运行以下代码

    [code="java"]
    package com.zte.httpclient.test;

    import java.io.FileInputStream;
    import java.io.IOException;

    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.PostMethod;

    public class HttpClientGetDWRData {

    /**
     * @param args
     * @throws IOException 
     * @throws HttpException 
     */
    public static void main(String[] args) throws HttpException, IOException {
        // TODO Auto-generated method stub
        HttpClient client = new HttpClient();
        PostMethod  method = new PostMethod("http://localhost:8080/dwr/dwr/call/plaincall/Demo.sayHello.dwr");
        method.setRequestBody(new FileInputStream("postdata.txt"));
        int statusCode = client.executeMethod(method);      
    
        System.out.println("得到的dwr响应信息如下:");
        System.out.println(method.getResponseBodyAsString());
    
    
    
    }
    

    }

    [/code]

    postdata.txt文件内容如下:
    [code="java"]
    callCount=1
    page=/dwr/simpletext/index.html
    httpSessionId=
    scriptSessionId=
    c0-scriptName=Demo
    c0-methodName=sayHello
    c0-id=0
    c0-param0=string:测试httpclient如何获取dwr的数据
    batchId=0

    [/code]

    得到的打印信息就是

    得到的dwr响应信息如下:
    throw 'allowScriptTagRemoting is false.';
    //#DWR-INSERT
    //#DWR-REPLY
    dwr.engine._remoteHandleCallback('0','0',"Hello, \u6D4B\u8BD5httpclient\u5982\u4F55\u83B7\u53D6dwr\u7684\u6570\u636E");

    "Hello, \u6D4B\u8BD5httpclient\u5982\u4F55\u83B7\u53D6dwr\u7684\u6570\u636E"这个信息就是dwr返回的数据

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题