Hello Experts,
We are trying to call the REST API to get some objects from the application server. The code we have can authenticate fine against the app server (we verify this by seeing a unique session ID), however when we try to run a "simple" POST to get some entities, the app server returns HTML instead of JSON. The HTML itself contains an error message saying "Javascript is disabled". The query is the same one that swagger generates.
For this simple example, we want to retrieve all Person objects. We have a ASP.NET web application, where clicking a button calls the API to get the objects.
Private Function GetWebSession() As String Try Dim OutputSessionID As String Dim inputData As String inputData = "{""AuthString"": ""Module=DialogUser;User=xxxxx;Password=xxxxx""}" Dim url As String = GetSettings.URLLogin Dim HttpRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(url), System.Net.HttpWebRequest) HttpRequest.Method = "Post" HttpRequest.Accept = "application/json" HttpRequest.Timeout = 300000 Dim inputEncoded = Encoding.ASCII.GetBytes(inputData) HttpRequest.GetRequestStream.Write(inputEncoded, 0, inputEncoded.Length) Dim cookie As New Cookie cookie.Domain = "xxxxxxx.xx.xx.com" cookie.Name = "SessionVariable" cookie.Value = "wsession" objcontainer.Add(cookie) HttpRequest.CookieContainer = objcontainer Dim HttpResponse As System.Net.HttpWebResponse = CType(HttpRequest.GetResponse(), System.Net.HttpWebResponse) Dim receiveStream As Stream = HttpResponse.GetResponseStream() Dim readStream As New StreamReader(receiveStream, Encoding.UTF8) Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer() Dim jsonobject = serializer.DeserializeObject(readStream.ReadToEnd()) OutputSessionID = jsonobject("sessionId") jsonobject = Nothing readStream = Nothing receiveStream = Nothing HttpRequest = Nothing HttpResponse = Nothing Return OutputSessionID Catch ex As Exception Throw ex End Try End Function Private Sub btnfilter_Click(sender As Object, e As EventArgs) Handles btnfilter.Click Try Dim url As String = "http://xxxxxxx.xxx.xxx.com:80/AppServer/api/entities/Person?loadType=Default" Dim HttpRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(url), System.Net.HttpWebRequest) HttpRequest.Method = "Post" HttpRequest.ContentType = "application/json" HttpRequest.Timeout = 300000 HttpRequest.ContentLength = 0 HttpRequest.CookieContainer = objcontainer ) Dim HttpResponse As System.Net.HttpWebResponse = CType(HttpRequest.GetResponse(), System.Net.HttpWebResponse) Dim receiveStream As Stream = HttpResponse.GetResponseStream() Dim readStream As New StreamReader(receiveStream, Encoding.UTF8) Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer() Dim jsonobject = serializer.DeserializeObject(readStream.ReadToEnd()) readStream = Nothing receiveStream = Nothing HttpRequest = Nothing HttpResponse = Nothing Catch ex As Exception lblnorecordsfound.Text = ex.Message End Try End Sub
Any help on why this is would be much appreciated