title: Post parameters during asmx web service call
body: <p>I am trying to make a web service call to following address: <a href="http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate" rel="nofollow">http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate</a></p>
  
  <p>However, I get <code>WebException : Protocol Error</code>. So, I need some help to find where I went wrong. Thanks.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      try
      {
          string FromCurrency = "GBP";
          string ToCurrency = "ALL";
  
          string postString = string.Format("FromCurrency={0}&amp;ToCurrency={1}", FromCurrency, ToCurrency);
          const string contentType = "application/x-www-form-urlencoded";
          System.Net.ServicePointManager.Expect100Continue = false;
  
          // Creates an HttpWebRequest for the specified URL. 
          HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate");
          req.ContentType = "text/xml;charset=\"utf-8\"";
          req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
          req.Method = "POST";
          req.ContentLength = postString.Length;
          req.Referer = "http://webservicex.net";
  
              StreamWriter requestWriter = new StreamWriter(req.GetRequestStream());
              requestWriter.Write(postString);
              requestWriter.Close();
  
              StreamReader responseReader = new StreamReader(req.GetResponse().GetResponseStream());
              string responseData = responseReader.ReadToEnd();
  
              responseReader.Close();
              req.GetResponse().Close();
      }
  
      catch (WebException ex)
      {
          Response.Write("\r\nWebException Raised. The following error occured : {0}" + ex.Status);
      }
      catch (Exception exc)
      {
          Response.Write("\nThe following Exception was raised : {0}" + exc.Message);
      }
  }
  </code></pre>