Search code examples
asp.net-web-apiasp-classic

How to consume a asp.net web api in classic asp?


I have a sample web API want to consume it in asp file, please guide me with the steps to consume web API in classic asp.


Solution

  • Below is the asp code.

      <%
      Dim Id
      Id = Request.QueryString("Id")
    
      url = "http://localhost:50464/api/values/"+Id
    
      Dim oXMLHttp
      Set oXMLHttp=Server.Createobject("MSXML2.ServerXMLHTTP.6.0")
      oXMLHttp.open "GET", url,false
      oXMLHttp.setRequestHeader "Content-Type", "application/json"
      oXMLHttp.send 
      response.write oXMLHttp.responseText
      Set oXMLHttp = Nothing
      %>
    

    API url: http://localhost:50464/api/values