初始化
This commit is contained in:
59
BLV_Studio/HttpMothod.vb
Normal file
59
BLV_Studio/HttpMothod.vb
Normal file
@@ -0,0 +1,59 @@
|
||||
Imports System.IO
|
||||
Imports System.Net
|
||||
Imports System.Text
|
||||
|
||||
Public NotInheritable Class HttpMothod
|
||||
|
||||
''' <summary>
|
||||
''' Post请求
|
||||
''' </summary>
|
||||
''' <param name="url">目标接口网址</param>
|
||||
''' <param name="data">传输数据</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function PostData(ByVal url As String, ByVal data As String) As String
|
||||
ServicePointManager.Expect100Continue = False
|
||||
Dim request As HttpWebRequest = WebRequest.Create(url)
|
||||
'//Post请求方式
|
||||
request.Method = "POST"
|
||||
|
||||
'内容类型
|
||||
request.ContentType = "application/x-www-form-urlencoded"
|
||||
'将URL编码后的字符串转化为字节
|
||||
Dim encoding As New UTF8Encoding()
|
||||
Dim bys As Byte() = encoding.GetBytes(data)
|
||||
'设置请求的 ContentLength
|
||||
request.ContentLength = bys.Length
|
||||
'获得请 求流
|
||||
Dim newStream As Stream = request.GetRequestStream()
|
||||
newStream.Write(bys, 0, bys.Length)
|
||||
newStream.Close()
|
||||
'获得响应流
|
||||
Dim sr As StreamReader = New StreamReader(request.GetResponse().GetResponseStream)
|
||||
Return sr.ReadToEnd
|
||||
End Function
|
||||
|
||||
|
||||
Public Shared Function PostData2(ByVal url As String, ByVal data As String) As String
|
||||
ServicePointManager.Expect100Continue = False
|
||||
Dim request As HttpWebRequest = WebRequest.Create(url)
|
||||
'//Post请求方式
|
||||
request.Method = "POST"
|
||||
|
||||
'内容类型
|
||||
request.ContentType = "application/json"
|
||||
'将URL编码后的字符串转化为字节
|
||||
Dim encoding As New UTF8Encoding()
|
||||
Dim bys As Byte() = encoding.GetBytes(data)
|
||||
'设置请求的 ContentLength
|
||||
request.ContentLength = bys.Length
|
||||
'获得请 求流
|
||||
Dim newStream As Stream = request.GetRequestStream()
|
||||
newStream.Write(bys, 0, bys.Length)
|
||||
newStream.Close()
|
||||
'获得响应流
|
||||
Dim sr As StreamReader = New StreamReader(request.GetResponse().GetResponseStream)
|
||||
Return sr.ReadToEnd
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user