My code should provide some information to the server using php script.
Basically, I want to call www.sitename.com/example.php?var1=1&var2=2&var3=3 , but I donβt want the browser to open, so Process.Start(URL); will not work.
Since I came to this site in order to find out and not get answers, basically, I will explain what I have done so far and the mistakes that I have received. If you still know the solution, feel free to skip the next part.
I looked around and saw a solution for using POST:
ASCIIEncoding encoding=new ASCIIEncoding(); string postData="var1=1&var2=2&var3=3"; byte[] data = encoding.GetBytes(postData);
However, I need to use GET not POST . At first, I decided that the solution could be to change myRequest.Method = "POST"; on GET , but this did not work, because GET does not work, it retrieves data from the URL.
So, I tried changing the previous code to:
HttpwebRequest myRequest= (HttpWebRequest)WebRequest.Create("http://localhost/site.php" + postData); Stream newStream = myRequest.GetRequestStream(); newStream.Close()
According to the logic, that it will call a URL which (hopefully) initiates a GET_ request to the php script, and then life will be a dandy. However, this led to the following error:
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.dll An unhandled exception of type 'System.Net.ProtocolViolationException' occurred in System.dll Additional information: Cannot send a content-body with this verb-type.
Any help is appreciated and thanks.