title: In C#, is it possible to open a URL in the background, without opening a browser?
body: <p>My code needs to supply some information to a server via a php script.</p>
  
  <p>Basically I want to call <code>www.sitename.com/example.php?var1=1&amp;var2=2&amp;var3=3</code> but I don't want the browser to open, so <code>Process.Start(URL);</code> won't work.</p>
  
  <p>Since I come to this site to learn and not to get answers, mostly, I will explain what I've done so far and the errors I have gotten. If you know a solution anyway, feel free to skip the next part.</p>
  
  <p>I have looked around, and I saw a solution for using POST:</p>
  
  <pre><code>ASCIIEncoding encoding=new ASCIIEncoding();
  string postData="var1=1&amp;var2=2&amp;var3=3";
  byte[]  data = encoding.GetBytes(postData);
  
  // Prepare web request...
  HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/site.php");
  myRequest.Method = "POST";
  myRequest.ContentType="application/x-www-form-urlencoded";
  myRequest.ContentLength = data.Length;
  Stream newStream=myRequest.GetRequestStream();
  
  // Send the data.
  newStream.Write(data,0,data.Length);
  newStream.Close();
  </code></pre>
  
  <p>However, I require the use of <code>GET</code> not <code>POST</code>. At first I thought the solution might be to change <code>myRequest.Method = "POST";</code> to <code>GET</code>, but this didn't work because that's not how <code>GET</code> works, it pulls data from the URL.</p>
  
  <p>So, then I attempted to change the previous code to:</p>
  
  <pre><code>HttpwebRequest myRequest= (HttpWebRequest)WebRequest.Create("http://localhost/site.php" + postData);
  Stream newStream = myRequest.GetRequestStream();
  newStream.Close()
  </code></pre>
  
  <p>Under the logic that it would call the URL, which would (hopefully) initiate the GET_ request on the php script, and then life would be dandy. This however resulted in the following error:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>Any help is appreciated, and thanks.</p>