Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi

I searched the forum and I found what I needed [Link],

but I can't get it to work:

 

I rewrote the code a little for my needs:

Dim webReq As HttpWebRequest
Dim reqStm As StreamWriter
Dim postData As String = ""

webReq = DirectCast(WebRequest.Create(URL), HttpWebRequest)
webReq.Method = "POST"
reqStm = New StreamWriter(webReq.GetRequestStream())

For Each Param As KeyValuePair(Of String, String) In Params
postData &= "&" & Param.Key & "=" & System.Web.HttpUtility.UrlEncode(Param.Value)
Next
postData = postData.Remove(0, 1)

reqStm.Write(postData)
reqStm.Flush()
reqStm.Close()
reqStm.Dispose()
Dim Content As String = New StreamReader(webReq.GetResponse().GetResponseStream()).ReadToEnd

 

The URL is http://arokh.dnsalias.org/Programs/AniTracker/Test.php

and its only purpose is to print the $_POST array with print_r().

 

But the $_POST array is always empty.

  • Leaders
Posted

Here is a really simple feedback agent I wrote in C# (I've inlined it and translated it to VB for you).


[Color=Green]'The variables used to initialize post are already declared or parameters [/Color]
[Color=Green]'Strings should be formatted for a URI[/Color]
[Color=Blue]Dim [/Color]post [Color=Blue]As String [/Color]= _
"&type=" & Uri.EscapeUriString(feedbackType) &
"&followup=" & Uri.EscapeUriString(requestReply) &
"&email=" & Uri.EscapeUriString(email) &
"&version=" & Uri.EscapeUriString(appVersion) &
"&message=" & Uri.EscapeUriString(message)
[Color=Blue]Dim [/Color]postBuffer [Color=Blue]As Byte[/Color]() = [Color=Green]'Then we get the text in a binary format. I believe that PHP prefers ASCII.[/Color]
System.Text.Encoding.ASCII.GetBytes(post);

[Color=Green]'Create and initialize the request[/Color]
[Color=Green]'Note that the URL is not hardcoded.[/Color]
[Color=Blue]Dim [/Color]request [Color=Blue]As [/Color]HttpWebRequest = _
[Color=Blue]DirectCast[/Color](WebRequest.Create(feedbackUrl), HttpWebRequest)
request.UserAgent = "My Program Agent"
request.Method = "POST"

[Color=Green]'Write POST data to request[/Color]
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = postBuffer.Length
[Color=Blue]Dim [/Color]requestStream [Color=Blue]As [/Color]Stream = request.GetRequestStream()
requestStream.Write(postBuffer, 0, postBuffer.Length)
requestStream.Close()

[Color=Green]'Execute request and read response.[/Color]
[Color=Blue]Dim [/Color]response [Color=Blue]As [/Color]HttpWebResponse = _
[Color=Blue]DirectCast[/Color](request.GetResponse(), HttpWebResponse)
ReadResponse(response)

postBuffer = [Color=Blue]Nothing[/Color]
[/Code]

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...