Rest API : passing the window.location.href in the REST uri -


i have rest api used trough jsonp due cross domain issues , i've implemeted errorlogger catches every error happens on page , posts server uri error logger :

user/{userid}/message/{errormessage}/browser/{browser}/browserver/{browserver}/secure/{secure}/os/{os}/location/{location}" 

the location variable problematic , how can pass window.location.href in uri ?

i've tried escape,encodeuri,encodeuricomponent have base64 ?

escaping sequence uris defined in section 2.4.1 of rfc2396 (uniform resource identifiers):

an escaped octet encoded character triplet, consisting of percent character "%" followed 2 hexadecimal digits representing octet code. example, "%20" escaped encoding us-ascii space character.     escaped     = "%" hex hex    hex         = digit | "a" | "b" | "c" | "d" | "e" | "f" |                          "a" | "b" | "c" | "d" | "e" | "f" 

this rfc defines reserved characters path component in section 3.3:

within path segment, characters "/", ";", "=", , "?" reserved. 

so need use encodeuricomponent() because escape() has been deprecated , encodeuri() does not escape reserved characters need escaped per rfc excerpt above.

the example below shows encodeuricomponent() escaping slashes (these characters cause problems facing):

>>> escape('//'); "//"  >>> encodeuri('//'); "//"  >>> encodeuricomponent('//'); "%2f%2f" 

however please note if possible, should use post instead of get. correct method use in rest (and in general), sending data client server (post) rather getting them server (get).

using post allow avoid additional problem. length of uris limited in common web servers, sooner or later encounter request long uri either gets trimmed or throws error. switching post allow keep uri clean , keep data in body of message instead of uri. see answers question details on uri length limits.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -