public class Test { public Test() throws HttpException, IOException {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost("127.0.0.1",80,"http");
PostMethod post = new PostMethod("/index.html");
NameValuePair name = new NameValuePair("username","sdaf");
post.setRequestBody(new NameValuePair[]{name});
int t = client.executeMethod(post);
System.out.println(t); //输出 200

post.releaseConnection();
GetMethod get = new GetMethod("/ok.asp");
client.executeMethod(get);
System.out.println(get.getResponseBodyAsString()); //这里没输出
get.releaseConnection();
} public static void main(String[] args) throws HttpException, IOException {
new Test();
}}

解决方案 »

  1.   

    >public   Test()   throws   HttpException,   IOException   {
    >HttpClient   client   =   new   HttpClient();
    >client.getHostConfiguration().setHost("127.0.0.1",80,"http");
    >PostMethod   post   =   new   PostMethod("/index.html");
    >NameValuePair   name   =   new   NameValuePair("username","sdaf");
    >post.setRequestBody(new   NameValuePair[]{name});
    >int   t   =   client.executeMethod(post);
    >System.out.println(t);   //输出   200 
    这里要用马上用post.getResponseBodyAsString()来得到回显内容,
    。。
      

  2.   

    > public       Test()       throws       HttpException,       IOException       { 
    > HttpClient       client       =       new       HttpClient(); 
    > client.getHostConfiguration().setHost("127.0.0.1",80,"http"); 
    > PostMethod       post       =       new       PostMethod("/index.html"); 
    > NameValuePair       name       =       new       NameValuePair("username","sdaf"); 
    > post.setRequestBody(new       NameValuePair[]{name}); 
    > int       t       =       client.executeMethod(post); 
    > System.out.println(t);       //输出       200   
    这里要用马上用post.getResponseBodyAsString()来得到回显内容,我这个表单是提交给 ok.asp我想知道的是 我的值 有没有 传给 ok.asp 就可以了
      

  3.   

    ok.asp<%  
    name=Request.Form("username")
    %>
    <%= name%>如果值传到这里了GetMethod get = new GetMethod("/ok.asp");
    client.executeMethod(get);
    System.out.println(get.getResponseBodyAsString()); //这里没输出
    get.releaseConnection();怎么得不到内容
      

  4.   

    如果想在index.html中向ok.jsp来提交,那么,要先get index.html,传参后再post到ok.jsp才行,看你的代码,应该是把参数提交到index.html。如果有服务器有redirect,还要把它的信息取出来,然后再get相应的页面才行。
    希望对你能有所帮助。
      

  5.   

    晕,,说的我有点乱了我是把参数提交到index.html 了呀是不是要让它自动提交表单呢