Salve, ho la necessità di caricare un file da un programma scritto appunto in vb.net , però al momento di prelevare la risposta mi da il codice di tutta la pagina e non la risposta (anche se faccio una pagina con form che punta ad un' altra pagina che stampa a video solo il risultato, niente codici) e in più i file non vengono caricati. Ho provato fin' ora questi due metodi:
codice:
Dim request As WebRequest = WebRequest.Create("http://sito.com/pagina.php")
' Set the Method property of the request to POST.
request.Method = "POST"
' Create POST data and convert it to a byte array.
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(tuttifile(attuale))
' Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded"
' Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length
' Get the request stream.
Dim dataStream As Stream = request.GetRequestStream()
' Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length)
' Close the Stream object.
dataStream.Close()
' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.
dataStream = 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()
MsgBox(responseFromServer)
' Display the content.
' Clean up the streams.
reader.Close()
dataStream.Close()
response.Close()
e
codice:
Dim web As New System.Net.WebClient()
Try
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes("PAR1=primo&PAR2=secondo")
Dim res As Byte() = web.UploadData("http://www.sitoweb.com", "POST", d)
Dim s As String
s = System.Text.Encoding.ASCII.GetString(res)
Me.TextBox1.Text = s
Catch ex As Exception
Debug.Print(ex.Message)
End Try