2011-03-14 70 views
6
httpRequest.Open "POST", "www.example.com/handle.asp", False 
httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
httpRequest.send data 
postResponse = httpRequest.response 

我該如何處理上述代碼的帖子。在handle.asp中。在句柄中,我想要將要發送的數據添加到該數據中,然後將某些內容發回給調用頁面?如何在asp中發送和處理Http Post?

回答

16

@Uzi:下面是一個例子 -

somefile.asp調用handle.asp這是處理腳本:

handle.asp
Option Explicit 

Dim data, httpRequest, postResponse 

data = "var1=somevalue" 
data = data & "&var2=someothervalue" 
data = data & "&var3=someothervalue" 

Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP") 
httpRequest.Open "POST", "http://www.example.com/handle.asp", False 
httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
httpRequest.Send data 

postResponse = httpRequest.ResponseText 

Response.Write postResponse ' or do something else with it 

Option Explicit 

Dim var1, var2, var3 

var1 = Request.Form("var1") 
var2 = Request.Form("var2") 
var3 = Request.Form("var3") 

' Silly example of a condition/test ' 
If var1 = "somecondition" Then 
    var1 = var1 & " - extra text" 
End If 

' .. More processing of the other variables .. ' 

' Processing/validation done... ' 
Response.Write var1 & vbCrLf 
Response.Write var2 & vbCrLf 
Response.Write var3 & vbCrLf 
0

完全按照自己的處理髮布數據通常使用ASP,通過使用Request.Form("parameter")來讀取POST值,並隨心所欲地執行任何操作。

您只需確保以處理腳本中的數據返回,該格式可以通過發出POST請求的腳本輕鬆解碼/使用。