Arokh Posted November 24, 2007 Posted November 24, 2007 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. Quote
Leaders snarfblam Posted November 25, 2007 Leaders Posted November 25, 2007 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] Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.