0
我想发布2个变量到一个PHP脚本,然后返回在网站上显示的文本。VB.NET http响应
我VB6,我做到了这一点,它工作得很好。 有人可以告诉我如何在VB.NET中做到这一点?
Public Function GetHTTPResponse() As String
Dim sPost$
sPost$ = "http://www.somedomain.com/somescript.php"
sPost$ = sPost$ & "?variable1=MYVAR1"
sPost$ = sPost$ & "&variable2=MYVAR2"
'=======================================================
'"?" Prefix 1st Variable, "&" prefix for subsequent vars
'=======================================================
Dim iPos&
iPos = InStr(sPost, "?")
If (iPos = 0) Then
Exit Function
End If
Dim sDomain$
sDomain$ = Left$(sPost, (iPos - 1))
'====================================
'Pack the post data into a byte array
'====================================
Dim sPostData As String
sPostData = Right$(sPost, Len(sPost) - iPos)
Debug.Print sPostData
Dim bytpostdata() As Byte
pBuildPostData bytpostdata(), sPostData
'=============================
'Write the byte into a variant
'=============================
Dim varPostData As Variant
varPostData = bytpostdata
'=================
'Create the Header
'=================
Dim sHeader$
sHeader = "application/x-www-form-urlencoded" + Chr(10) + Chr(13)
'=============
'Post the data
'=============
Dim xmlhttp As Object
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", sDomain, False
xmlhttp.setRequestHeader "Content-Type", sHeader
xmlhttp.sEnd varPostData
Dim sRet$
sRet = xmlhttp.responseText
GetHTTPResponse = sRet
End Function