avoid objXmlHttp json string escaped in classic asp

378 views Asked by At

I have a classic asp page which retreives encoded token from web service, something like this:

objXmlHttp.Open "POST", "http://some_web_service", False
objXmlHttp.SetRequestHeader "Content-Type", "application/json"
objXmlHttp.Send something
If objXmlHttp.Status = 200 Then
    response.write ("objXmlHttp.ResponseText:"&objXmlHttp.ResponseText)

I see in my objXmlHttp.ResponseText slashes escaped like this

"...rVw1s\/Qn30..." (see "\" and "/" after "s").

When I send this token via query string (Response.Redirect) to an asp.net mvc controller of another web application I receive it with the backslash escaped too, like this

"...rVw1s\\/Qn30...", that breaks.

I'd like not to do replace, if is it possible, not in asp (sending token) and not in asp.net mvc (receiving token).

Is it possible to avoid to receive escaped slash in objXmlHttp in classic asp?

Or maybe I'm doing something wrong or missing something...

1

There are 1 answers

0
Falco On BEST ANSWER

Thank @Lankymart for advice about Json wrapping the data to send:

worked this way:

  1. in ASP sender doing Server.URLEncode of my token (without this not worked...)*

  2. Serialize the encoded token using aspJSON in a simple object (something in format like {"token":"myXYZtoken"}), sent serialized object to my MVC action method.

  3. In MVC Action receiver method deserilized using Newtonsoft JsonConvert into dynamic object

  4. found into the object the "token" property in the right formatted way.

*N.B: Only Server.URLEncode of the original token without wrapping in Json object did not worked.