title: Migrating short vb6 code that uses WinHttp.WinHttpRequest to c# or vb.net
body: <p>can someone please guide me how to convert that vb6 code to c# or visual basic.net. i have tried to to use the  <code>System.Net.WebRequest()</code> class but with no success (everything i treys throws another exception so i think that adding my c# code will not be helpful).</p>
  
  <p>this code works fine (i tested it with the vba editor).</p>
  
  <p><strong>clarification: I DONT EXPECT SOME TO DO MY JOB i just need to understand the equivilent methods of the first 11 rows in  <code>GetHTTPResponse()</code> function to <code>System.Net.WebRequest()</code> class medhods , it will be enough and i will be able to handle it alone from that point.</strong></p>
  
  <p>thank you very much for your time and consideration.</p>
  
  <pre><code>Function ReadToken(s)
      Dim X()
      ReDim X(0)
      s = Replace(s, Chr(34), "")
      bRes = False
      Set RegExp = CreateObject("VBScript.RegExp")
      RegExp.IgnoreCase = True
      RegExp.Pattern = "token\:(.+?),type\:(.+?),expires_in\:(.+?)"
  
      bRes = RegExp.test(s)
      If bRes Then
          Set oMatches = RegExp.Execute(s)
          ReDim X(2)
          X(0) = oMatches(0).subMatches(0)
          X(1) = oMatches(0).subMatches(1)
          X(2) = oMatches(0).subMatches(2)
      End If
      ReadToken = X
  
  End Function
  
  Function GetHTTPResponse(ByVal Id As Long) As String
  ' On Error Resume Next
      Const username = "username"
      Const password = "password"
      sURL = "https://api.exoclick.com/v1/login"
      Set oXMLHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
      With oXMLHTTP
          .Open "Post", sURL, False
          .setRequestHeader "Content-Type", "application/json"
          params = "{""username"":" &amp; Chr(34) &amp; username &amp; Chr(34) &amp; ", ""password"":" &amp; _
                  Chr(34) &amp; password &amp; Chr(34) &amp; "}"
          .send params
          If .Status = 200 Then
              Response = .ResponseText
              Token = ReadToken(Response)
              Authorization = "{""type"":" &amp; Chr(34) &amp; Token(1) &amp; _
                              Chr(34) &amp; ",""token"":" &amp; Chr(34) &amp; Token(0) &amp; Chr(34) &amp; "}"
              .abort
              sURL = "https://api.exoclick.com/v1/statistics/advertiser/date"
              params = "{""campaignid"":" &amp; Id &amp; "}"
              .Open "GET", sURL, False
              .setRequestHeader "Content-Type", "application/json"
              .setRequestHeader "Authorization", Authorization
              .send params
              GetHTTPResponse = .ResponseText
          End If
      End With
      Set oXMLHTTP = Nothing
  End Function
  </code></pre>