Hello,
I'm trying to write a vb.net command-line application that will upload files to a partner's website via a HTTP form. The problem I am having is that I have no idea how to do a HTTP POST where the input type = file (file to be uploaded). I can do a HTTP POST with all the other variables, just not the file uploading (input type=file).
Could somebody please tell me what I am doing wrong and/or need to change? Thanks!!!!
Here is the URL that contains the basic HTML to post and upload a file: http://66.228.120.89/temp/temp.html
Here is the code I have so far:
I'm trying to write a vb.net command-line application that will upload files to a partner's website via a HTTP form. The problem I am having is that I have no idea how to do a HTTP POST where the input type = file (file to be uploaded). I can do a HTTP POST with all the other variables, just not the file uploading (input type=file).
Could somebody please tell me what I am doing wrong and/or need to change? Thanks!!!!
Here is the URL that contains the basic HTML to post and upload a file: http://66.228.120.89/temp/temp.html
Here is the code I have so far:
VB.NET:
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Namespace Examples.System.Net
Public Class WebRequestGetExample
Public Shared Sub Main()
Dim var1, var2, var3, var4, var5, var6 As String
Dim filename As String
Dim URL_topost As String
URL_topost = "http://www1.badongo.com/index.php?page=upload&"
var1 = "desc=gt_vid&"
var2 = "toc=1&"
var3 = "mature=NO&"
var4 = "UL_ID=801799385.1486042519.1141984650&"
var5 = "filename=c:\tow.jpg"
' Create a request for the URL.
Dim request As WebRequest = WebRequest.Create(URL_topost & var1 & var2 & var3 & var4 & var5)
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials
' Get the response.
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
' Display the status.
Console.WriteLine(response.StatusDescription)
' 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()
' Display the content.
Console.WriteLine(responseFromServer)
' Cleanup the streams and the response.
reader.Close()
dataStream.Close()
response.Close()
End Sub 'Main
End Class 'WebRequestGetExample
End Namespace