2014-09-23 91 views
0

我已經建立了一個URL在Mailgun控制面板網絡掛鉤,並建立了一個腳本,當反彈出現,從Mailgun追加與HTTP郵政txt文件的URL。我已經從一個測試頁面提交一個HTTP後提交表單和表單數據被寫入到txt文件精測試了它 - 但是當我觸發來自Mailgun測試一個新行被寫入,但收集的Request.Form出現空着。Mailgun網絡掛接和傳統的ASP

我缺少從Mailgun在HTTP郵政的東西,我想從它那裏得到的Request.Form集合的方式嗎?

<% 
strWebhookData = "///// New Entry ///" & vbnewline 
For Each Item In Request.Form 
     fieldName = Item 
     fieldValue = Request.Form(Item) 
     Response.write fieldName & " " & fieldValue 
     strWebhookData = strWebhookData & fieldName &" = " & fieldValue & vbnewline   
    Next 
Response.write strWebhookData 

set fs=Server.CreateObject("Scripting.FileSystemObject") 
    set f=fs.OpenTextFile(Server.MapPath("bounces.txt"),8,true) 
    f.WriteLine(vbnewline & strWebhookData) 
    f.Close 
set f=Nothing 
set fs=Nothing 

%> 

回答

0

不知道這是否會工作,但使用此代碼嘗試

For Each x In Request.Form 
    fieldName = x 
    fieldValue = Request.Form(x) 
    Response.write fieldName & " " & fieldValue 
    strWebhookData = strWebhookData & fieldName &" = " & fieldValue & vbnewline   
Next 
+0

感謝您的 - 但該腳本確實從測試頁面獲取表單變量我使用後到該頁面,但沒有捕捉從Mailgun HTTP郵報什麼。無論如何,我會嘗試你的建議。 – 2014-09-23 09:41:55

+0

什麼是Mailgun HTTP Post代碼的外觀?你可以檢查是否有任何事情實際上是通過開發工具(chrome)或Firebug(FireFox)傳輸的 – pee2pee 2014-09-23 09:43:40

+0

這是HTTP_RAW的輸出(如果有幫助的話)。 內容長度:4230 內容類型:多部分/格式的數據;邊界= 2adc9741-1b71-4442-9377-170f6562daea 接受編碼:gzip 用戶代理:mailgun/TREQ-0.2.1 – 2014-09-23 10:10:59

0

I'm,我真的鴕鳥政策記得在那裏我找到它:

Response.Expires=0 
Response.Buffer = TRUE 
Response.Clear 
byteCount = Request.TotalBytes 
RequestBin = Request.BinaryRead(byteCount) 
Dim UploadRequest 
Set UploadRequest = CreateObject("Scripting.Dictionary") 
BuildUploadRequest RequestBin 

「一些例子變數

strEvent = UploadRequest.Item("event").Item("Value") 
strEmail = UploadRequest.Item("recipient").Item("Value") 

'您可以在mailgun日誌選項卡上找到所有變量

Sub BuildUploadRequest(RequestBin) 
    'Get the boundary 
    PosBeg = 1 
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13))) 
    boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg) 
    boundaryPos = InstrB(1,RequestBin,boundary) 
    'Get all data inside the boundaries 
    Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--"))) 
     'Members variable of objects are put in a dictionary object 
     Dim UploadControl 
     Set UploadControl = CreateObject("Scripting.Dictionary") 
     'Get an object name 
     Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition")) 
     Pos = InstrB(Pos,RequestBin,getByteString("name=")) 
     PosBeg = Pos+6 
     PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34))) 
     Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) 
     PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename=")) 
     PosBound = InstrB(PosEnd,RequestBin,boundary) 
     'Test if object is of file type 
     If PosFile<>0 AND (PosFile<PosBound) Then 
      'Get Filename, content-type and content of file 
      PosBeg = PosFile + 10 
      PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34))) 
      FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) 
      'Add filename to dictionary object 
      UploadControl.Add "FileName", FileName 
      Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:")) 
      PosBeg = Pos+14 
      PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13))) 
      'Add content-type to dictionary object 
      ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) 
      UploadControl.Add "ContentType",ContentType 
      'Get content of object 
      PosBeg = PosEnd+4 
      PosEnd = InstrB(PosBeg,RequestBin,boundary)-2 
      Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg) 
      Else 
      'Get content of object 
      Pos = InstrB(Pos,RequestBin,getByteString(chr(13))) 
      PosBeg = Pos+4 
      PosEnd = InstrB(PosBeg,RequestBin,boundary)-2 
      Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) 
     End If 
     'Add content to dictionary object 
    UploadControl.Add "Value" , Value 
     'Add dictionary object to main dictionary 
    UploadRequest.Add name, UploadControl 
     'Loop to next object 
     BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary) 
    Loop 

End Sub 

'String to byte string conversion 
Function getByteString(StringStr) 
For i = 1 to Len(StringStr) 
    char = Mid(StringStr,i,1) 
    getByteString = getByteString & chrB(AscB(char)) 
Next 
End Function 

'Byte string to string conversion 
Function getString(StringBin) 
getString ="" 
For intCount = 1 to LenB(StringBin) 
    getString = getString & chr(AscB(MidB(StringBin,intCount,1))) 
Next 
End Function 

0

的數據是多部分/形式數據; - 我用的AspUpload從他們的形式讀取變量

Set Upload = Server.CreateObject("Persits.Upload.1") 
Upload.Save 

strEvent  = Upload.Form("event") 
sBounceEmail = Upload.Form("recipient")