title: posting data to asmx page using vb.net
body: <p>Greeting,
  am trying to post data to asmx webservice using vb.net but am getting the following error "Error WebException The remote server returned an error: (500) Internal Server Error."</p>
  
  <p>The vb.net coding I used is:</p>
  
  <pre><code>Private Function ConnectApi() As String
      Dim hwReq As HttpWebRequest
      Dim hwRes As HttpWebResponse
  
  
  
      Dim gsLogin As String = "xxxxxxx"
      Dim gsPassword As String = "xxxxxxxxx"
      Dim gsCode As String = "xxxxxxxxx"
      Dim mTransactionId As String = "521"
      Dim mBaseCurrency As String = "USD"
      Dim mPaymentValue As Decimal = 2.1
      Dim mDateTime As Date = Now.Date
  
      Dim mCustomValue As Integer = 15
  
      'Dim strPostData As String = String.Format("sub={0}&amp;login={1}&amp;password={2}&amp;limit={3}", Server.UrlEncode(ApiSub), Server.UrlEncode(ApiUsername), Server.UrlEncode(ApiPassword), Server.UrlEncode(ApiLimit))
      Dim strPostData As String = String.Format("gsLogin={0}&amp;gsPassword={1}&amp;gsCode={2}&amp;mTransactionId={3}&amp;mBaseCurrency={4}&amp;mPaymentValue={5}&amp;mDateTime={6}&amp;mCustomValue={7}", Server.UrlEncode(gsLogin), Server.UrlEncode(gsPassword), Server.UrlEncode(gsCode), Server.UrlEncode(mTransactionId), Server.UrlEncode(mBaseCurrency), Server.UrlEncode(mPaymentValue), Server.UrlEncode(mDateTime), Server.UrlEncode(mBaseCurrency), Server.UrlEncode(mCustomValue))
  
  
  
      Dim strResult As String = ""
      Try
          'https:/gscash.com/gateway/staging/gsprocess.asmx?wsdl
  
          hwReq = DirectCast(WebRequest.Create("https://gscash.com/gateway/staging/gsprocess.asmx"), HttpWebRequest)
  
  
  
  
  
          hwReq.Method = "POST"
          hwReq.ContentType = "application/x-www-form-urlencoded"
          hwReq.ContentLength = strPostData.Length
  
          Dim arrByteData As Byte() = ASCIIEncoding.ASCII.GetBytes(strPostData)
          hwReq.GetRequestStream().Write(arrByteData, 0, arrByteData.Length)
  
          hwRes = DirectCast(hwReq.GetResponse(), HttpWebResponse)
          If hwRes.StatusCode = HttpStatusCode.OK Then
              Dim srdrResponse As New StreamReader(hwRes.GetResponseStream(), Encoding.UTF8)
              Dim strResponse As String = srdrResponse.ReadToEnd().Trim()
  
              strResult = strResponse
  
          End If
      Catch wex As WebException
          strResult = "Error WebException " + wex.Message
      Catch ex As Exception
          strResult = "Error Exception " + ex.Message
      Finally
          hwReq = Nothing
          hwRes = Nothing
      End Try
  
      Return strResult
  End Function
  </code></pre>