VB.NET 2005 – WebClient.UploadString – POST Data Appearing Not To Be Sent
March 15th, 2008 by Oliver - Tagged with VB.NET, WebClient - Posted in Web Development
Once again ran into this issue while working on a small VB.NET project for a client.
Problem: When using the webclient to upload a string of data to a PHP/ASP/etc script with the following code (or similar), you aren’t able to pick the posted data up within your receiving script:
Dim wc As New WebClient
wc.UploadString(url, data)
wc.UploadString(url, data)
I found a few articles resorting to other code (usually a lot more / complex�code, i.e. converting string to bytes and then using the UploadData method) to get this resolved.However the fix is simple. Tell the script what data your posting�by adding some headers!�Modify your code by adding this extra line inbetween defining the WebClient and using the UploadString method:
Dim wc As New WebClient
wc.Headers.Add(“Content-Type”,“application/x-www-form-urlencoded”)
wc.UploadString(url, data)
wc.Headers.Add(“Content-Type”,“application/x-www-form-urlencoded”)
wc.UploadString(url, data)







