title: Calling REST API from Visual Basic
body: <p>I keep getting a 404 error.
  It works fine if I call the REST API from SoapUI.</p>
  <p>I’m using Visual Basic VS2015.
  I have a sample function which I’m calling from a simple forms project. This is just to get the REST API to work. The REST API call will go into a Visual Basic Windows Service once I get it working,</p>
  <p>There is a form named <code>form1</code> which has a <code>txtURL</code> textbox, a button to call <code>sub Main()</code>, and an output textbox called <code>textbox1</code>.</p>
  <pre><code>Public Shared Sub Main()
          Try
              Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(Form1.txtURL.Text), HttpWebRequest)
              With myHttpWebRequest
                  .Method = &quot;POST&quot;
                  .ContentType = &quot;application/json&quot;
                  .Accept = &quot;application/json&quot;
                  .MediaType = &quot;jsonp&quot;
   
                  With .Headers
                      .Add(&quot;Authorization&quot;, &quot;Bearer ABCDabcd1234=&quot;)
                      .Add(&quot;riskLevelStatus&quot;, &quot;6897&quot;)
                      .Add(&quot;userId&quot;, &quot;12345&quot;)
                      .Add(&quot;applicationName&quot;, &quot;MyApp&quot;)
                  End With
   
              End With
              Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
   
              Form1.TextBox1.Text = Form1.TextBox1.Text &amp; myHttpWebResponse.ToString() &amp; vbCrLf
   
              myHttpWebResponse.Close()
              'Catch exception if trying to add a restricted header.
          Catch e As ArgumentException
              Form1.TextBox1.Text = Form1.TextBox1.Text &amp; &quot;Error-ArgumentException: &quot; &amp; e.Message &amp; vbCrLf
          Catch e As WebException
              Form1.TextBox1.Text = Form1.TextBox1.Text &amp; &quot;Error-WebException: &quot; &amp; e.Message &amp; vbCrLf
              If e.Status = WebExceptionStatus.ProtocolError Then
                  Form1.TextBox1.Text = Form1.TextBox1.Text &amp; &quot;Error-Status Code: &quot; &amp; CType(e.Response, HttpWebResponse).StatusCode &amp; vbCrLf
                  Form1.TextBox1.Text = Form1.TextBox1.Text &amp; &quot;Error-Status Description: &quot; &amp; CType(e.Response, HttpWebResponse).StatusDescription &amp; vbCrLf
                  Form1.TextBox1.Text = Form1.TextBox1.Text &amp; &quot;Error-Server: &quot; &amp; CType(e.Response, HttpWebResponse).Server &amp; vbCrLf
              End If
          Catch e As Exception
              Form1.TextBox1.Text = Form1.TextBox1.Text &amp; &quot;Error-Exception: &quot; &amp; e.Message &amp; vbCrLf
          End Try
      End Sub 'Main
  </code></pre>
  <p>Here is what is outputted to <code>textbox1</code>:</p>
  <blockquote>
  <p>Error -WebException: The remote server returned an Error: (400) Bad Request.</p>
  <p>Error -Status Code: 400</p>
  <p>Error -Status Description</p>
  <p>Error -Server</p>
  </blockquote>
  <p>What should be returned is a single line JSON, similar to this:</p>
  <pre><code>{“quid”: “jhgdsjdshg-hdbw-akjhjk-kdhbfsihg”}
  </code></pre>
  <p>It works fine when calling from SoapUI.</p>
  <p>I believe this issue is how do I add data to the body?</p>