1Dim strPostURL = "http://www.google.com"
2
3 AddText("URL TO POST: " + strPostURL)
4
5 Dim requestStream As Stream = Nothing
6 Dim fileStream As FileStream = Nothing
7 Dim uploadResponse As Net.HttpWebResponse = Nothing
8
9 Try
10
11 Dim uploadRequest As Net.HttpWebRequest = CType(Net.HttpWebRequest.Create(strPostURL), Net.HttpWebRequest)
12 uploadRequest.Method = Net.WebRequestMethods.Http.Post
13 ' UploadFile is not supported through an Http proxy
14 ' so we disable the proxy for this request.
15 uploadRequest.Proxy = Nothing
16
17 requestStream = uploadRequest.GetRequestStream()
18 fileStream = File.Open("c:\temp\MyActions_Partial_Feed_Format.xml", FileMode.Open)
19
20 Dim buffer(1024) As Byte
21 Dim bytesRead As Integer
22 While True
23 bytesRead = fileStream.Read(buffer, 0, buffer.Length)
24 If bytesRead = 0 Then
25 Exit While
26 End If
27 requestStream.Write(buffer, 0, bytesRead)
28 End While
29
30 ' The request stream must be closed before getting the response.
31 requestStream.Close()
32
33 uploadResponse = uploadRequest.GetResponse()
34 Dim responseReader As StreamReader = New StreamReader(uploadRequest.GetResponse.GetResponseStream())
35 Dim x As String = responseReader.ReadToEnd()
36 responseReader.Close()
37 AddText(x)
38
39
40
41 Catch ex As UriFormatException
42 AddText(ex.Message)
43 Catch ex As IOException
44 AddText(ex.Message)
45 Catch ex As Net.WebException
46 AddText(ex.Message)
47 Finally
48 If uploadResponse IsNot Nothing Then
49 uploadResponse.Close()
50 End If
51 If fileStream IsNot Nothing Then
52 fileStream.Close()
53 End If
54 If requestStream IsNot Nothing Then
55 requestStream.Close()
56 End If
57 End Try