You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Erica Zhang <er...@cs.ubc.ca> on 2007/03/18 02:40:01 UTC

Why I could not get the response properly?

Hi,
I send a POST request to the server. The response should be in text/xml 
format. However, I could not get the response properly. I also tried to 
use other methods, such as getResponseAsStream and etc. They all could 
not work. I do not know why.

The server is Tomcat + JSP + servlet. I use http client to develop the 
client .

The code is like below:

public void SendReceivePOST() {

        System.out.println("SendReceivePOST is called ");

    HttpClient client = new HttpClient();
    System.out.println("this.url is " + this.url);
    PostMethod method_tmp= new PostMethod(this.url);
 
    .... //this block is to add parameters to POST request ;
 
     
    try {
        System.out.println("try block begins");
              // Execute the method.
              int statusCode = client.executeMethod(method_tmp);

              if (statusCode == HttpStatus.SC_OK) {

                  this.response = method_tmp.getResponseBodyAsString() ;
                 System.out.println("this.response is" + this.response) ;
              }
        ....
  }

For the server, the servlet just write following string as  response:
<root><index>7</index><data_lists><list>---</list><list>Jason 
Hunter</list><list>Richard Monson - Haefel</list><list>Kathy 
Sierra</list><list>Michael Morrison</list><list>Craig 
Larman</list><list>Hanumant Deshmukh</list></data_lists></root>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Why I could not get the response properly?

Posted by Roland Weber <ht...@dubioso.net>.
Hello Erica,

since I have no idea what the server is supposed to respond,
I can't see a problem with what it is printing. If you can
access the server using a browser, I suggest that you follow
the instructions in the Client HTTP Programming Primer:

http://wiki.apache.org/jakarta-httpclient/ForAbsoluteBeginners


If you can't use a browser to access the server, you should
read that document anyway. It lists plenty of possible errors,
such as not establishing a session before posting, dropping
cookies that are required for the session, authentication,...

If none of that solves your problem, please send a detailed
description of the expected behavior vs. the actual behavior,
and a wire log of the headers:
http://jakarta.apache.org/commons/httpclient/logging.html

cheers,
  Roland


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org