HTTP Post with .NET CF VB

  • Thread starter Philippe Schnyder
  • Start date
P

Philippe Schnyder

Hi

I'm doing one of my first VB.net app for WM5 and I'm stuck with
following problem: I'd like to have my app to do a HTTP(S) Post
Request with the following properties (as it was as an HTML File):

<form method="Post" action="https://privateserver/cgi-bin/sms/
send.pl">
<input name="username" type="hidden" value="myusername">
<input name="password" type="hidden" value="mypassword"
<input type="hidden" name="originator" value="phonenumber">
<input type="hidden" name="action" value="sendsms"></p>
<input name="number" type="text" value="now from a textbox in my VB
app">
<textarea name="message" value="too a textbox"></textarea>
<input type="submit" value="Send">
</form>

Those data need to be sended urlencoded in encoding latin1 (=
iso-8859-1)

I introduced System.Net.HTTPWebRequest:
Dim SendSMS As System.Net.HttpWebRequest =
System.Net.HttpWebRequest.Create("https://ndev9.ethz.ch/cgi-bin/sms/
send.pl/send.pl")
SendSMS.Method = "POST"
SendSMS.SendChunked = True
SendSMS.ContentType = "application/x-www-form-urlencoded"
but I've no idea where to pass the parameters and how to handle HTTP
answer?

Thank you for your time

Philippe
 
A

Andre Rode

Hi

I'm doing one of my first VB.net app for WM5 and I'm stuck with
following problem: I'd like to have my app to do a HTTP(S) Post
Request with the following properties (as it was as an HTML File):

<form method="Post" action="https://privateserver/cgi-bin/sms/
send.pl">
<input name="username" type="hidden" value="myusername">
<input name="password" type="hidden" value="mypassword"
<input type="hidden" name="originator" value="phonenumber">
<input type="hidden" name="action" value="sendsms"></p>
<input name="number" type="text" value="now from a textbox in my VB
app">
<textarea name="message" value="too a textbox"></textarea>
<input type="submit" value="Send">
</form>

Those data need to be sended urlencoded in encoding latin1 (=
iso-8859-1)

I introduced System.Net.HTTPWebRequest:
Dim SendSMS As System.Net.HttpWebRequest =
System.Net.HttpWebRequest.Create("https://ndev9.ethz.ch/cgi-bin/sms/
send.pl/send.pl")
SendSMS.Method = "POST"
SendSMS.SendChunked = True
SendSMS.ContentType = "application/x-www-form-urlencoded"
but I've no idea where to pass the parameters and how to handle HTTP
answer?

Thank you for your time

Philippe

Hi
I don't know if this works in the .NET Compact Framework, but it's worth
a try


Dim sURL As String = "http://yoururl.com"
Dim myHttpWebRequest As HttpWebRequest = WebRequest.Create(sURL)

Dim postData As String = "data1=this&data2=is&data3=an&data4=example"

myHttpWebRequest.Method = "POST"
Dim encodedData As New System.Text.ASCIIEncoding()

Dim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes(postData)
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
myHttpWebRequest.ContentLength = byteArray.Length
Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)
newStream.Close()
' The response object of 'HttpWebRequest' is assigned to a
'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType
(myHttpWebRequest.GetResponse(), HttpWebResponse)

' Displaying the contents of the page to the console
Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
Console.WriteLine(outputData)
s = s & outputData
count = streamRead.Read(readBuff, 0, 256)
End While
' Release the response object resources.
streamRead.Close()
streamResponse.Close()
myHttpWebResponse.Close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top