0

我正在尝试将 2 个变量发布到 php 脚本,然后返回网站上显示的文本。

我是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
4

1 回答 1

0

我终于在这里找到了解决方案:

http://www.pcreview.co.uk/forums/using-webclient-webrequest-webresponse-post-postdata-and-get-result-t1222629.html

于 2012-11-27T06:37:15.130 回答