从VB.net中的GET / POST请求加载结果

问题描述 投票:2回答:1

我想开发一个使用在线API,GET和POST请求的程序,我想知道如何在程序中发出请求(没有用户看到网页),然后将结果下载到程序中我可以解析它们

vb.net api post get
1个回答
3
投票

你正在寻找WebRequest课程。这个例子改编自msdn文档:

Dim request As WebRequest = WebRequest.Create("http://www.example.com/example.html")
' Get the response.
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
© www.soinside.com 2019 - 2024. All rights reserved.