【问题标题】:VB.NET http responseVB.NET http 响应
【发布时间】:2012-11-15 06:37:46
【问题描述】:

我正在尝试将 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

【问题讨论】:

    标签: php vb.net http webrequest


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 2016-07-13
    • 1970-01-01
    相关资源
    最近更新 更多