hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: Probem executing Query
Date Fri, 04 Jun 2004 01:00:11 GMT
Hi Satya,

setQueryString() assumes that the content is already URL encoded and it 
is then sent as part of the request line, i.e.:

POST /path?QUERY_STRING  HTTP/1.1

My guess is that you want to send the query string as part of the 
message body.  You can do this with:

mehod.setRequestBody(userModel.getQueryString());

Mike

On Jun 3, 2004, at 7:13 PM, http-client@jrapid.com wrote:

> I am using the following code:
> HttpClient client = new HttpClient(connMgr);
> client.setHostConfiguration(hostConfig);
> PostMethod method = new PostMethod(tokenURL);
> method.setQueryString( userModel.getQueryString() );
> client.executeMethod(method);
> byte[] responseBody = method.getResponseBody();
> method.releaseConnection();
> The response I get is : Request format is invalid: .
> --------------
> However,  If I run the same query using the following code:
>           con.setRequestMethod("POST");
>           con.setDoOutput(true);
>           con.setDoInput(true);
>           OutputStreamWriter writer = new 
> OutputStreamWriter(con.getOutputStream());
>           writer.write( userModel.getQueryString() );
>           writer.flush();
>           writer.close();
>
>           InputStream resultStream = con.getInputStream();
>
>           BufferedReader reader = new BufferedReader(new 
> InputStreamReader(resultStream));
>           StringBuffer aResponse = new StringBuffer();
>           String aLine = reader.readLine();
>
>           while(aLine != null){
>               aResponse.append(aLine);
>               aLine = reader.readLine();
>           }
>           resultStream.close();
>           releaseConnection(con);
>           String retData = aResponse.toString();
>
> I get the expected string as a response.
> What I am doing wrong in using HttpClient?  Any Idea?.
> -Satya
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


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


Mime
View raw message