客服电话
18058309210
01 | Imports System.Net |
02 | Imports System.io |
03 |
04 | Public Class HttpSend |
05 | ''' <summary> |
06 | ''' post方法 |
07 | ''' </summary> |
08 | ''' <param name="url">服務器地址</param> |
09 | ''' <param name="param">參數</param> |
10 | ''' <returns></returns> |
11 | ''' <remarks></remarks> |
12 | Public Shared Function postSend( ByVal url As String , ByVal param As String ) As String |
13 |
14 | Dim myEncode As System.Text.Encoding = System.Text.Encoding.GetEncoding( "UTF-8" ) |
15 |
16 | Dim postBytes() As Byte = System.Text.Encoding.ASCII.GetBytes(param) |
17 |
18 | Dim req As HttpWebRequest = HttpWebRequest.Create(url) |
19 | req.Method = "POST" |
20 | req.ContentType = "application/x-www-form-urlencoded;charset=UTF-8" |
21 | req.ContentLength = postBytes.Length |
22 |
23 | Try |
24 | Using reqStream As Stream = req.GetRequestStream() |
25 | reqStream.Write(postBytes, 0, postBytes.Length) |
26 | End Using |
27 |
28 | Using res As WebResponse = req.GetResponse() |
29 | Using sr As StreamReader = New StreamReader(res.GetResponseStream(), myEncode) |
30 | Dim strResult As String = sr.ReadToEnd() |
31 | Return strResult |
32 | End Using |
33 | End Using |
34 |
35 | Catch ex As WebException |
36 | Return "無法連接到服務器" & Chr(13) & Chr(10) & "錯誤信息:" & ex.Message |
37 | End Try |
38 |
39 |
40 | End Function |
41 | ''' <summary> |
42 | ''' get方法 |
43 | ''' </summary> |
44 | ''' <param name="url">地址</param> |
45 | ''' <param name="param">參數</param> |
46 | ''' <returns></returns> |
47 | ''' <remarks></remarks> |
48 | Public Shared Function getSend( ByVal url As String , ByVal param As String ) As String |
49 | Dim address As String = url & "?" & param |
50 | Dim uri As Uri = New Uri(address) |
51 | Dim webReq As WebRequest = WebRequest.Create(uri) |
52 |
53 | Try |
54 | Using webResp As HttpWebResponse = DirectCast (webReq.GetResponse(), HttpWebResponse) |
55 | Using respStream As Stream = webResp.GetResponseStream() |
56 | Using objReader As StreamReader = New StreamReader(respStream, System.Text.Encoding.GetEncoding( "UTF-8" )) |
57 | Dim strRes As String = objReader.ReadToEnd() |
58 | Return strRes |
59 | End Using |
60 | End Using |
61 | End Using |
62 |
63 | Catch ex As WebException |
64 | Return "無法連接到服務器" & Chr(13) & Chr(10) & "錯誤信息:" & ex.Message |
65 | End Try |
66 |
67 |
68 | End Function |
69 |
70 | End Class |