hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James.Goulst...@ubs.com
Subject Posted data losing the last 2 characters when you submit an @ symbol ?
Date Fri, 10 Dec 2004 15:38:16 GMT
Hi,

Has anyone got any thoughts on the following?

Very simply we have an application that receives HTTP Requests and then forwards these on
using HttpClient. When submitting POST data via HttpClient the @ symbol (and as far as we
can tell only the @ symbol) causes 2 characters to be lost when the request is received by
the application we are sending to. The parameters are always lost from the end of the last
data to be posted.

We've debugged into the HttpClient code as well as using the logging and as far as we can
see the data is not truncated at any point. We've tried setting the content length after thinking
that @ is encoded to %40 and therefore maybe its not expecting 3 characters but just 1 and
therefore missing off the last 2 characters but this didn't help (the content length always
seems to set correctly).

We're using the setRequestBody on PostMethod and effectively setting name value pairs which
we encode. However if we take the input stream straight from the request and set this using
setRequestBody we don't get any problems. We've also tried different encoders after noticing
that the inputstream method doesn't encode the @ symbol to %40. We've also tried converting
our name/value pair data into an InputStream and then setting that via setRequestBody. We've
also tried not having any encoding but on other characters such as !£$ etc. this either causes
the applications we call via httpclient to hang and not respond or to recieve no data at all.
We have also tried setting the content type / character encoding on the header etc.

This doesn't work

            Map parms = request.getParameterMap();
            Iterator iter = parms.keySet().iterator();
            StringBuffer postData = new StringBuffer();
            String characterEncoding = request.getCharacterEncoding();
            if (characterEncoding == null) {
                characterEncoding = org.apache.commons.httpclient.HttpConstants.DEFAULT_CONTENT_CHARSET;
            }
            while (iter.hasNext()) {
                String name = (String) iter.next();
                
                String encodedName = URLEncoder.encode(name,characterEncoding);
                String[] value = (String[]) parms.get(name);
                for (int i = 0; i < value.length; i++) {
                    String encodedValue = URLEncoder.encode(value[i], characterEncoding);
                    if (postData.length() > 0) {
                        postData.append("&" + encodedName + "=" + encodedValue);
                    } else {
                        postData.append(encodedName + "=" + encodedValue);
                    }
                }
            }
            method.setRequestBody(postData.toString());

This works fine

...
            InputStream stream = request.getInputStream();
            BufferedInputStream inputStream = new BufferedInputStream(stream);
            postMethod.setRequestBody(inputStream);    
...


Thanks in advance for your help,

James

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.


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


Mime
View raw message