Imports System.Net Imports System.io Public Class HttpSend ''' <summary> ''' post方法 ''' </summary> ''' <param name="url">服務(wù)器地址</param> ''' <param name="param">參數(shù)</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function postSend(ByVal url As String, ByVal param As String) As String Dim myEncode As System.Text.Encoding = System.Text.Encoding.GetEncoding("UTF-8") Dim postBytes() As Byte = System.Text.Encoding.ASCII.GetBytes(param) Dim req As HttpWebRequest = HttpWebRequest.Create(url) req.Method = "POST" req.ContentType = "application/x-www-form-urlencoded;charset=UTF-8" req.ContentLength = postBytes.Length Try Using reqStream As Stream = req.GetRequestStream() reqStream.Write(postBytes, 0, postBytes.Length) End Using Using res As WebResponse = req.GetResponse() Using sr As StreamReader = New StreamReader(res.GetResponseStream(), myEncode) Dim strResult As String = sr.ReadToEnd() Return strResult End Using End Using Catch ex As WebException Return "無法連接到服務(wù)器" & Chr(13) & Chr(10) & "錯(cuò)誤信息:" & ex.Message End Try End Function ''' <summary> ''' get方法 ''' </summary> ''' <param name="url">地址</param> ''' <param name="param">參數(shù)</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function getSend(ByVal url As String, ByVal param As String) As String Dim address As String = url & "?" & param Dim uri As Uri = New Uri(address) Dim webReq As WebRequest = WebRequest.Create(uri) Try Using webResp As HttpWebResponse = DirectCast(webReq.GetResponse(), HttpWebResponse) Using respStream As Stream = webResp.GetResponseStream() Using objReader As StreamReader = New StreamReader(respStream, System.Text.Encoding.GetEncoding("UTF-8")) Dim strRes As String = objReader.ReadToEnd() Return strRes End Using End Using End Using Catch ex As WebException Return "無法連接到服務(wù)器" & Chr(13) & Chr(10) & "錯(cuò)誤信息:" & ex.Message End Try End Function End Class
友情鏈接:106短信平臺 | 發(fā)短信平臺 | 短信接口平臺 | 短信接口平臺哪個(gè)好 | 國際短信 | 短信通 | 短信接口應(yīng)用
關(guān)于我們 | 產(chǎn)品與服務(wù) | 解決方案 | 客戶案例 | 聯(lián)系我們 | 幫助指南 | 付款方式
Copyright © 2008-2018 短信通 . 速度網(wǎng)絡(luò)有限公司 短信接口應(yīng)用第一平臺 All rights reserved. 浙ICP備10040624號-2