הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Tuesday, July 5, 2016 11:37 PM
Is there any reason why VB.net 2015 would not send the actual POST data?
I post to a very simple PHP (I've tried many variants of the PHP page as well)
<?php
echo 'Post Data is : ';
var_dump($_POST);
?>
Other Forms and apps written in other languages recieve the above data correct, while in VB I've tried WebClient, WebRequest, HttpWebRequest using every variation I could find. They all clearly access the page and retrieve the data but none actually receive any post information.
The response in VB.Net is "Post Data is : array(0) {}"
Is there something I am missing with this? a setting? a reference?
I've tried all the below and more:
Dim client As New WebClient()
Dim data As Byte() = Encoding.ASCII.GetBytes("field=value")
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim responseArray As Byte() = client.UploadData(URL, data)
Dim responseFromServer As String = Encoding.ASCII.GetString(responseArray)
Dim client As New WebClient()
Dim data As New Specialized.NameValueCollection()
data.Add("field", "value")
Dim responseArray As Byte() = client.UploadValues(URL, "POST", data)
Dim responseFromServer As String = Encoding.Default.GetString(responseArray)
Dim request As WebRequest = WebRequest.Create(URL)
request.Method = "POST"
Dim data As Byte() = Encoding.UTF8.GetBytes("field=value")
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = data.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(data, 0, data.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
reader.Close()
All replies (3)
Wednesday, July 6, 2016 1:07 AM
Have you used a network sniffer like WireShark (it's free) to verify the outgoing packets do not contain post data?
I did read in a thread that if a URL is redirected to another site then the post data gets dropped also.
A possible solution from this link, converted to VB using Telerik online, is the below code.
Dim URI As String = "http://www.myurl.com/post.php"
Dim myParameters As String = "param1=value1¶m2=value2¶m3=value3"
Using wc As New WebClient()
wc.Headers(HttpRequestHeader.ContentType) = "application/x-www-form-urlencoded"
Dim HtmlResult As String = wc.UploadString(URI, myParameters)
End Using
My guess is you have already tested the PHP post using some other method to verify the code at the website works for receiving a Post from a client.
La vida loca
Wednesday, July 6, 2016 1:25 AM
I just re-read your post. You are posting but you say none of the objects used receive post data. I thought Post was posting data to a website and Get was getting data from a website. Maybe I'm wrong as I don't use this.
La vida loca
Wednesday, July 6, 2016 2:38 AM
I suggest that you use Fiddler to debug and see if you can spot anything in the raw HTML traffic with solutions that are successful as opposed to the one that is not successful.