INVIO A PHP TRAMITE POST

martedì 01 ottobre 2013 - 16.21
Tag Elenco Tags  VB.NET

PITGORICO Profilo | Newbie

Salve ragazzi
HO un problema che n n riesco proprio a risolvere.
Devo passare tramite POST una stringa ad una pagina PHP.
Pero ho una serie di problemi che non capisco.
HO scritto il seguente codice:

Dim httpWebRequest = DirectCast(WebRequest.Create("http://www.miosito.com/import.php?datidainviare"), HttpWebRequest)

httpWebRequest.ContentType = "text/json"
httpWebRequest.Method = "POST"
'httpWebRequest.Credentials = New NetworkCredential("utente", "password") ' Ho provato anche senza .....

Using streamWriter = New StreamWriter(httpWebRequest.getRequestStream())
Dim json As String = "stringa di dati da inviare in formato JSON, ma ho provato anche un semplice testo"
'Invio della richiesta
streamWriter.Write(json)
End Using

'Lettura della risposta

Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
Using streamReader = New StreamReader(httpResponse.GetResponseStream())
Dim responseText = streamReader.ReadToEnd()
MsgBox(responseText)
End Using

Ma dall'altra parte non arriva nulla !!!!
ho provato anche a inviare una stringa di testo modificando
httpWebRequest.ContentType = "text/json"
in
httpWebRequest.ContentType = "application/x-www-form-urlencoded"
ma niente!!!

Forse sbaglio a specificare lavariabile php in quel modo? (import.php?datidainviare")
Scusate ma non ho mai passato nulla da VB a Php e mi trovo un po in difficoltà... ho girato per il forum ma gli esempi che ho trovato presentano sostanzialmente gli stessi problemi?
DOve sbaglio ? :(
GRazie mille

grace Profilo | Newbie

Prova a spostare il parametro datidainviare a ad aggiungere ContentLenght:

Dim request As WebRequest = WebRequest.Create(""http://www.miosito.com/import.php")
request.Method = "POST"
Dim postData As String = "pippoplutopaperino"
postData = "datidainviare=" & "pippoplutopaperino"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()

PITGORICO Profilo | Newbie

Grazie mille
In effetti il problema era la Variabile PHP definita nel posto sbagliato....
In PHP deve stare 'dentro' al pacchetto inviato via POST...
Ma quando le cose non ti vengono in mente !!!

TKS
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5