我正在尝试将ebay-api事务通知接收到web服务器上托管的ASP中。通知以SOAP消息的形式发送,并且可以通过查询字符串发送到URL。通知必须用HTTP200OK来响应。我希望通知位于一个变量中,这样我就可以解析它并将其发送到系统的下一部分。
http://developer.ebay.com/DevZone/guides/ebayfeatures/Notifications/Notifications.html#ReceivingPlatformNotifications
在文档中,他们提到这是可能的,但他们给出的示例是订阅电子邮件服务器。这个ASP不一定需要发出SOAP请求,只需要接受来自ebay服务器的SOAP消息。
我正在学习ASP、SOAP和查询字符串,但如果能提供一些指导,我将不胜感激。谢谢
这应该是非常直接的,您的经典ASP页面将成为易趣通知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
,以确保您只收到预期源的发送消息(尽管这不是防弹的,因为信息可能会被伪造)。
有用的链接
访问请求的正文(很好的现有答案,解释了如何使用
Request.BinaryRead()
读取内容并将其转换为字符串,然后您可以在变量中使用该字符串或使用XMLDocument.LoadXML()
进行解析)如何在经典ASP中使用VBScript生成MD5(如果您想寻找一种验证MD5签名的方法)
这是我的notifications.asp中迄今为止的内容。当我试图通过Postman向它发送一个基本的SOAP帖子时,什么都没有发生。这看起来应该有效吗?
我在没有If语句检查SOAP头的情况下测试了这一点,并且只发布了常规字符串数据,它就可以工作了。所以二进制到字符串的转换和输出到文件都很好。现在我只需要用实际的ebayAPI通知来测试它
<%
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:inetpubwwwrootASPtestnotifications.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
%>