从 eBay api 接收 SOAP 通知到 ASP 变量?
Receiving SOAP notifications from eBay api into ASP variable?
我正在尝试将 ebay api 交易通知接收到托管在网络服务器上的 ASP 中。通知作为 SOAP 消息发送,并且可以发送到带有查询字符串的 URL。必须使用 HTTP 200 OK 响应通知。我希望通知落在一个变量中,以便我可以解析它并将其发送到系统的下一部分。
他们在文档中提到这是可能的,但他们提供的示例采用了订阅电子邮件服务器的方式。 ASP 不一定需要发出 SOAP 请求,只需接受来自 ebay 服务器的 SOAP 消息。
我正在研究 ASP、SOAP 和查询字符串,但如果能提供一点指导,我将不胜感激。谢谢!
这应该很简单,您的经典 ASP 页面将成为 eBay 通知的端点 API (只要您已将其配置为发送通知以及什么URL 发送到).
您应该可以使用简单的经典 ASP 页面进行测试
<%
Dim isPost: isPost = (UCase(Request.ServerVariables("REQUEST_METHOD") & "") = "POST")
Dim hasSoapAction
'Is it a HTTP POST?
If isPost Then
'Do we have a SOAPACTION header (check both because
'it can be either HTTP_ or HEADER_ depending on IIS version)?
hasSoapAction = ( _
Len(Request.ServerVariables("HEADER_SOAPACTION") & "") > 0 Or _
Len(Request.ServerVariables("HTTP_SOAPACTION") & "") > 0 _
)
If hasSoapAction Then
'Process the notification here.
'Use Request.BinaryRead to read the SOAP
End If
'Let eBay know we have received and processing the message.
Response.Status = "200 OK"
Else
'Return method not allowed
Response.Status = "405 Method Not Allowed"
End If
Response.End
%>
您可能还想检查 REMOTE_HOST
以确保您只收到预期来源的发送消息 (这不是万无一失的,因为信息可以是 spoofed).
有用的链接
Accessing a request's body (很好的现有答案,解释了如何使用 Request.BinaryRead()
读取内容并将其转换为字符串,然后您可以在一个变量或用于解析 XMLDocument.LoadXML()
).
How to generate MD5 using VBScript in classic ASP? (如果想看MD5签名的验证方法)
这是我目前 notifications.asp 中的内容。当我尝试通过 Postman 向它发送一个基本的 SOAP post 时,什么也没有发生。这看起来应该有效吗?
我在没有检查 SOAP headers 的 If 语句的情况下测试了这个,我 post 只编辑了常规字符串数据并且它有效。所以二进制到字符串的转换和输出到文件都很好。现在我只需要用实际的 ebay api 通知来测试它。 ;-)
<%
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "iso-8859-1"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
Dim isPost: isPost = (UCase(Request.ServerVariables("REQUEST_METHOD") & "") = "POST")
Dim hasSoapAction
'Is it a HTTP POST?
If isPost Then
'Do we have a SOAPACTION header?
hasSoapAction = (Len(Request.ServerVariables("HEADER_SOAPACTION") & "") > 0)
If hasSoapAction Then
'Process the notification here.
'Use Request.BinaryRead to read the SOAP
If Request.TotalBytes > 0 Then
Dim lngBytesCount, text
lngBytesCount = Request.TotalBytes
text = BytesToStr(Request.BinaryRead(lngBytesCount))
dim fs, tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile("C:\inetpub\wwwroot\ASPtest\notifications.txt")
tfile.WriteLine(text)
tfile.Close
set tfile=nothing
set fs=nothing
End If
End If
'Let eBay know we have received and processing the message.
Response.Status = "200 OK"
Else
'Return method not allowed
Response.Status = "405 Method Not Allowed"
End If
Response.End
%>
我正在尝试将 ebay api 交易通知接收到托管在网络服务器上的 ASP 中。通知作为 SOAP 消息发送,并且可以发送到带有查询字符串的 URL。必须使用 HTTP 200 OK 响应通知。我希望通知落在一个变量中,以便我可以解析它并将其发送到系统的下一部分。
他们在文档中提到这是可能的,但他们提供的示例采用了订阅电子邮件服务器的方式。 ASP 不一定需要发出 SOAP 请求,只需接受来自 ebay 服务器的 SOAP 消息。
我正在研究 ASP、SOAP 和查询字符串,但如果能提供一点指导,我将不胜感激。谢谢!
这应该很简单,您的经典 ASP 页面将成为 eBay 通知的端点 API (只要您已将其配置为发送通知以及什么URL 发送到).
您应该可以使用简单的经典 ASP 页面进行测试
<%
Dim isPost: isPost = (UCase(Request.ServerVariables("REQUEST_METHOD") & "") = "POST")
Dim hasSoapAction
'Is it a HTTP POST?
If isPost Then
'Do we have a SOAPACTION header (check both because
'it can be either HTTP_ or HEADER_ depending on IIS version)?
hasSoapAction = ( _
Len(Request.ServerVariables("HEADER_SOAPACTION") & "") > 0 Or _
Len(Request.ServerVariables("HTTP_SOAPACTION") & "") > 0 _
)
If hasSoapAction Then
'Process the notification here.
'Use Request.BinaryRead to read the SOAP
End If
'Let eBay know we have received and processing the message.
Response.Status = "200 OK"
Else
'Return method not allowed
Response.Status = "405 Method Not Allowed"
End If
Response.End
%>
您可能还想检查 REMOTE_HOST
以确保您只收到预期来源的发送消息 (这不是万无一失的,因为信息可以是 spoofed).
有用的链接
Accessing a request's body (很好的现有答案,解释了如何使用
Request.BinaryRead()
读取内容并将其转换为字符串,然后您可以在一个变量或用于解析XMLDocument.LoadXML()
).How to generate MD5 using VBScript in classic ASP? (如果想看MD5签名的验证方法)
这是我目前 notifications.asp 中的内容。当我尝试通过 Postman 向它发送一个基本的 SOAP post 时,什么也没有发生。这看起来应该有效吗?
我在没有检查 SOAP headers 的 If 语句的情况下测试了这个,我 post 只编辑了常规字符串数据并且它有效。所以二进制到字符串的转换和输出到文件都很好。现在我只需要用实际的 ebay api 通知来测试它。 ;-)
<%
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "iso-8859-1"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
Dim isPost: isPost = (UCase(Request.ServerVariables("REQUEST_METHOD") & "") = "POST")
Dim hasSoapAction
'Is it a HTTP POST?
If isPost Then
'Do we have a SOAPACTION header?
hasSoapAction = (Len(Request.ServerVariables("HEADER_SOAPACTION") & "") > 0)
If hasSoapAction Then
'Process the notification here.
'Use Request.BinaryRead to read the SOAP
If Request.TotalBytes > 0 Then
Dim lngBytesCount, text
lngBytesCount = Request.TotalBytes
text = BytesToStr(Request.BinaryRead(lngBytesCount))
dim fs, tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile("C:\inetpub\wwwroot\ASPtest\notifications.txt")
tfile.WriteLine(text)
tfile.Close
set tfile=nothing
set fs=nothing
End If
End If
'Let eBay know we have received and processing the message.
Response.Status = "200 OK"
Else
'Return method not allowed
Response.Status = "405 Method Not Allowed"
End If
Response.End
%>