hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ortwin Glück <...@odi.ch>
Subject Re: URL Encoding
Date Fri, 12 Jan 2007 08:44:00 GMT
Actually, that URLEncode does is encode into 
"application/x-www-form-urlencoded", which is not *exactly* URL 
encoding. That's where the + sign comes from. In practice this doesn't 
matter much, as you will be mostly encoding query string with this 
logic. And those are parsed by exactly these semantics. If however you 
have to encode a space character in the path part of the URL you MUST 
use %20 and + is invalid there. I think neither URI nor URLCodec are 
doing that correctly, really. And I doubt any server implementation is 
doing that correctly either. In practice I'd say that + and %20 are 
completely interchangeable. Maybe + being not specific to an encoding, 
while %20 is.

Ortwin



Ortwin Glück wrote:
> Saminda,
> 
> AFAIK the + character is interchangeable with %20 in HTTP URLs. (This 
> may not be true for generic URLs, however). As to your example: It's 
> encoded the wrong way! You must only encode the names and values BETWEEN 
> the ? = and ; characters! It's generally very wrong to run whole URLs / 
> the whole Query string through URLEncode. (Lots of people do that wrong 
> and don't understand what they are doing.)
> 
> Ortwin
> 
> Saminda Abeyruwan wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi Ortwin,
>>
>> When encoded with URLEncode.encode(); the space character is converted
>> to "+" sign, {JavaDoc}; but the rfc3986 (section 2.1) says, the "space
>> character should encoded to %x20". Seem this is a problem in
>> interoperability. Do you have an insight of this problem.
>>
>> Ex: "?op=EchoInt;int=4 2;" is encoded to %3Fop%3DEchoInt%3Bint%3D4+2%3B
>>
>> Thank you
>>
>> Saminda
>>
>> Ortwin Glück wrote:
>>> Hi Saminda,
>>>
>>> The colon (:) is a reserved character and must therefore be URL-escaped
>>> if it is used for anything else than separating the port from the host.
>>>
>>> In your case you should simply run the query part (everything after the
>>> ?) through java.net.URLEncoder.encode():
>>>
>>> String url =
>>> "http://localhost:8081/axis2/services/ProbeSpaceService.PathsEndpoint?constructReference/datespace/2006/11/18/16:10:00.000Z-19:30:42.000Z.html";

>>>
>>>
>>>
>>> int separator = url.indexOf('?');
>>> String path = url.substring(0, separator);
>>> String query = url.substring(separator+1);
>>>
>>> url = path +'?'+ URLEncoder.encode(query, "ASCII");
>>>
>>> Cheers
>>>
>>> Ortwin
>>>
>>> Saminda Abeyruwan wrote:
>>> Hi,
>>>
>>> We have a (WSDL2.0) complaint URL
>>>
>>>  http://localhost:8081/axis2/services/ProbeSpaceService.PathsEndpoint?constructReference/datespace/2006/11/18/16:10:00.000Z-19:30:42.000Z.html

>>>
>>>
>>>
>>> to send. But HttpClient gives me the following exception;
>>>
>>> =============================================================================

>>>
>>>
>>> org.apache.axis2.AxisFault: invalid port number; nested exception is:
>>>    org.apache.commons.httpclient.URIException: invalid port number;
>>> nested exception is:
>>>    org.apache.axis2.AxisFault: invalid port number; nested exception is:
>>>    org.apache.commons.httpclient.URIException: invalid port number
>>>    at
>>> org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)

>>>
>>>
>>>    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:497)
>>>    at
>>> org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:365)

>>>
>>>
>>>    at
>>> org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:295)

>>>
>>>
>>>    at
>>> org.example.pathsEndpoint.ProbeSpaceServiceStub.constructReference(ProbeSpaceServiceStub.java:164)

>>>
>>>
>>>    at 
>>> pathsEndpoint.PathsEndpointClient.main(PathsEndpointClient.java:30)
>>> Caused by: org.apache.axis2.AxisFault: invalid port number; nested
>>> exception is:
>>>    org.apache.commons.httpclient.URIException: invalid port number
>>>    at
>>> org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:338)

>>>
>>>
>>>    at
>>> org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:205)

>>>
>>>
>>>    ... 5 more
>>> Caused by: org.apache.commons.httpclient.URIException: invalid port
>>> number
>>>    at org.apache.commons.httpclient.URI.parseAuthority(URI.java:2225)
>>>    at org.apache.commons.httpclient.URI.parseUriReference(URI.java:1968)
>>>    at org.apache.commons.httpclient.URI.<init>(URI.java:165)
>>>    at
>>> org.apache.commons.httpclient.HttpMethodBase.getURI(HttpMethodBase.java:261)

>>>
>>>
>>>    at
>>> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:382) 
>>>
>>>
>>>    at
>>> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346) 
>>>
>>>
>>>    at
>>> org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:534)

>>>
>>>
>>>    at
>>> org.apache.axis2.transport.http.SOAPOverHTTPSender.send(SOAPOverHTTPSender.java:174)

>>>
>>>
>>>    at
>>> org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:334)

>>>
>>>
>>>
>>>    ... 6 more
>>> ==================================================================================

>>>
>>>
>>>
>>> This is due to the "6:10:00.000Z-19:30:42.000Z.html" part in the URL.
>>> Could you please give me a solution to escape these characters.
>>>
>>> Thank you
>>>
>>> Saminda
>> - ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> httpcomponents-dev-help@jakarta.apache.org
>>
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.2.2 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>
>> iD8DBQFFpyorYmklbLuW6wYRApBkAJ0XsxRMLq6h552cO9cMlhJTPnI1tQCgxwed
>> Iq7oUglvnG1G5nNm/K5fSyY=
>> =4X6v
>> -----END PGP SIGNATURE-----
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: 
>> httpcomponents-dev-help@jakarta.apache.org
>>
> 

-- 
[web]  http://www.odi.ch/
[blog] http://www.odi.ch/weblog/
[pgp]  key 0x81CF3416
        finger print F2B1 B21F F056 D53E 5D79 A5AF 02BE 70F5 81CF 3416

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


Mime
View raw message