# 웹훅 튜토리얼

## 튜토리얼

팝빌 Webhook 수신 VBScript 예제코드입니다. 팝빌 ASP SDK 예제코드에 포함된 ./Popbill/Linkhub/json2.asp를 사용하여 Webhook JSON Message를 처리합니다.

```vb
'DocumentRoot/connect.asp


<!--#include file="Popbill/Linkhub/json2.asp"-->


<%


If Request.TotalBytes > 0 Then


  Dim RequestBodyBytes
  RequestBodyBytes = Request.TotalBytes


  'JSON String을 JSON Object로 변환
  Set parse = JSON.parse(BytesToStr(Request.BinaryRead(RequestBodyBytes)))


  eventDT = parse.eventDT 'Webhook 실행일시
  eventType = parse.eventType 'Webhook 유형
  '추가적인 항목은 [Webhook 메시지 구성] 참조


  'Webhook 수신 성공처리를 위해 Response Message "OK" String 반환
  Response.Write "OK"


End If


'Byte 형태의 POST Request Body Message를 String으로 변환하는 함수
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 = "UTF-8"
    BytesToStr = Stream.ReadText
    Stream.Close
  Set Stream = Nothing
End Function


%>
```
