Author Topic: Request/retrieve post data from a webhook  (Read 83 times)

plokij909

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Request/retrieve post data from a webhook
« on: April 06, 2018, 02:22:39 AM »
Hi, I'm trying to use Stripe's WebHooks with Classic ASP and can't retrieve their POST JSON data when it hits my page.

Normal request.form() doesn't work. I've read there are ways to do it with BinaryRead.

Is there a better way using a Chilkat Library (would be great if Chilkat could add a WebHook example in the Stripe example page: http://rest-examples.chilkat.io/stripe/asp/default.cshtml)

Thanks

Chilkat

  • Administrator
  • Jr. Member
  • *****
  • Posts: 90
  • Karma: +4/-0
    • View Profile
Re: Request/retrieve post data from a webhook
« Reply #1 on: April 06, 2018, 11:21:58 AM »
You wouldn't use Chilkat to receive the information contained in the POST sent to your ASP page.  You would just use ASP for that.
In general, however your web page  is implemented (Classic ASP, ASP.NET, PHP, Perl, Python, Ruby, etc.) you would use that language's features to collect the incoming POST information.
At that point, you might use Chilkat, if appropriate, for anything.  For example, you might use Chilkat's JSON classes to parse the received JSON.

In Classic ASP, you might begin by examining the incoming data:

<html>
<body>

<%
    for each x in Request.Form
        Response.Write("<br>" & x & " = " & Request.Form(x))
    next
%>

</body>
</html>

plokij909

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Request/retrieve post data from a webhook
« Reply #2 on: April 06, 2018, 11:49:39 PM »
Hi,

I've tried looping through request.form - it doesn't work (it's blank). I've seen people using Request.BinaryRead, e.g. https://stackoverflow.com/questions/25991314/mailgun-webhooks-and-classic-asp

plokij909

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Request/retrieve post data from a webhook
« Reply #3 on: April 10, 2018, 08:17:10 PM »
Here's the code to use if anyone else is having troubles.


If Request.TotalBytes > 0 Then
  Dim lngBytesCount
  lngBytesCount = Request.TotalBytes
  jsonstring = BytesToStr(Request.BinaryRead(lngBytesCount))
End If

    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