我写了一个ASP脚本来生成JSON数据/字符串。如何将该数据发送到Web服务?我得到了以下信息,我无法访问服务器来注册任何DLL文件。我做了一些搜索,发现我应该使用XMLHttpRequest,但不知道该怎么做。
请帮忙。谢谢。
连接到网络服务 Web服务通过HTTP协议工作。建议此Web服务一旦投入生产,即使用安全套接字层(HTTPS)。该网络服务旨在使用网址:http://thedomain.com/api/push
网站在标头中使用身份验证令牌,以防止抓取工具干扰Web服务。发送数据时,添加名为HTTP_TOKENKEY的标头,其值为ABCDEFGHIJKL。这是建议使用HTTPS的一个原因。 Web服务将在请求的POST中查找JSON数据,并将JSON响应发送回客户端。
这是我到目前为止所拥有的
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
这冻结了,什么都不做
答案 0 :(得分:0)
以下是我之前根据您的情况发布的一些代码:
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