How to send a Json object (or string data) from xmlhttprequest using classic ASP?

I wrote ASP Script to generate JSON data / string. How to send this data to a web service? I was provided with the information below, and I do not have access to the server to register any DLL files. I did some searches and saw that I should use XMLHttpRequest, but I don’t know how to do it.

Please, help. Thanks.

Connecting to the web service The web service runs over HTTP. It is recommended that this web service, once in production, use the Secure Socket Layer (HTTPS). The web service is designed to work with the URL: http://thedomain.com/api/push

The site uses an authentication token in the header to discourage crawlers from using the web service. When sending data, add a header named HTTP_TOKENKEY with the value ABCDEFGHIJKL. This is one of the reasons why HTTPS is recommended. The web service will look for JSON data in POST requests and send JSON responses back to the client.

This is what I still have


strJSONToSend = theevent webserviceurl = "http://thedomain.com/api/push" Set objRequest = Server.createobject("MSXML2.XMLHTTP.3.0") objRequest.open "POST", webserviceurl, False objRequest.setRequestHeader "Content-Type", "application/json; charset=UTF-8" objRequest.setRequestHeader "HTTP_TOKENKEY","ABCDEFGHIJKLMNOPQ" objRequest.setRequestHeader "SOAPAction", webserviceurl results = objRequest.send (strJSONToSend) write (results) set objJSONDoc = nothing set objResult = nothing 

it freezes and does nothing

+4
source share
1 answer

Here is some code that I posted before this URL, adapted to your situation:

http://naterice.com/articles/69

 strJSONToSend = theevent webserviceurl = "http://thedomain.com/api/push" sResponseHTML = GetHTTP(strJSONToSend, webserviceurl) If len(HTTPErrorHandeler) > 0 Then strResponse = HTTPErrorHandeler Else strResponse = sResponseHTML End If Response.Write strResponse Function GetHTTP(sSendHTML, sURL) 'This script is provided under the Creative Commons license located' 'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not' 'be used for commercial purposes with out the expressed written consent' 'of NateRice.com' Set oHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP") oHTTP.Open "POST", sURL, false oHTTP.setRequestHeader "Content-Type", "application/json; charset=UTF-8" oHTTP.setRequestHeader "HTTP_TOKENKEY","ABCDEFGHIJKLMNOPQ" oHTTP.setRequestHeader "SOAPAction", webserviceurl On Error Resume Next oHTTP.send sSendHTML sHTTPResponse = oHTTP.responseText If Err.Number = 0 Then GetHTTP = sHTTPResponse Else GetHTTP = HTTPErrorHandeler End If On Error Goto 0 Set oHTTP = Nothing End Function Function HTTPErrorHandeler 'This script is provided under the Creative Commons license located' 'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not' 'be used for commercial purposes with out the expressed written consent' 'of NateRice.com' If Err.Number <> 0 Then HTTPErrorHandeler = "ERROR <br />" & _ " ERR Number: " & Err.Number & " <br />" & _ " ERR Description: " & Err.Description Else HTTPErrorHandeler = "" End If End Function 
0
source

All Articles