Page 1 of 1

Getting Bad Request

Posted: Fri Aug 01, 2014 3:06 am
by BladeZX
I am using VB.Net to get data from the service.

When I use this link: https://json.schedulesdirect.org/20131021/programs, I am sending in one request similar to this:

{"request":["SH015157750000"]}

I am sending my token as well but I get a bad request error back.

When I use the same function call to get the schedules for a station id (https://json.schedulesdirect.org/20131021/schedules), it works fine.

I can run the same data through a JSON web page called Postman and it works fine. No idea why I get bad request.

What am I doing wrong?

Thanks

Re: Getting Bad Request

Posted: Fri Aug 01, 2014 4:28 am
by rkulagow
If you give me the timestamp I can pull the server-side logs.

Re: Getting Bad Request

Posted: Fri Aug 01, 2014 6:27 am
by BladeZX
Would have been 07/31/2014 around 6:20-6:30 PM EST.
My user is bladezx

I appreciate it

Re: Getting Bad Request

Posted: Fri Aug 01, 2014 5:50 pm
by rkulagow
I worked with Blade offline and this was resolved as a client-side implementation issue. Blade can further provide the details of what was required to make the code functional.

Re: Getting Bad Request

Posted: Sat Aug 02, 2014 6:43 am
by BladeZX
I was getting this error:

8/1/2014 6:24:27 PM : v1.0.0.0 - Send_JSON_Request(): ERROR - Caught this web exception - {"response":"DEFLATE_REQUIRED","code":1002,"serverID":"AWS-SD-web.1","message":"Did not receive Accept-Encoding: deflate in request","datetime":"2014-08-01T22:21:07Z"}

Here is the VB.Net code I am using that seems to work. Hopefully it will help out someone else.

Code: Select all

            Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
            req.ContentType = contentType
            req.Method = method
            If Not headers Is Nothing Then
                req.Headers = headers
                If IsDebugOn() Then
                    LogDebug("Send_JSON_Request(): request headers set")
                End If
            End If
            req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate")

            If Not jsonData Is Nothing Then
                Dim dataBytes As Byte() = System.Text.UTF8Encoding.UTF8.GetBytes(jsonData)
                If Not dataBytes Is Nothing Then
                    If IsDebugOn() Then
                        LogDebug("Send_JSON_Request(): dataBytes.Length --> " & dataBytes.Length)
                    End If
                    req.ContentLength = dataBytes.Length
                    Dim stream As Stream = Nothing
                    stream = req.GetRequestStream()
                    stream.Write(dataBytes, 0, dataBytes.Length)
                    stream.Close()
                    If IsDebugOn() Then
                        LogDebug("Send_JSON_Request(): request data bytes stream set")
                    End If
                End If
                dataBytes = Nothing
            End If

            Dim response As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)

            Dim responseStream As Stream = response.GetResponseStream()
            If response.ContentEncoding.ToLower().Contains("gzip") Then
                responseStream = New GZipStream(responseStream, CompressionMode.Decompress)
            ElseIf response.ContentEncoding.ToLower().Contains("deflate") Then
                responseStream = New DeflateStream(responseStream, CompressionMode.Decompress)
            End If

            'Dim Reader As New StreamReader(responseStream, Encoding.[Default])

            'Dim response As WebResponse = req.GetResponse()
            Dim responseStatus As String = (DirectCast(response, HttpWebResponse).StatusDescription)
            If IsDebugOn() Then
                LogDebug("Send_JSON_Request(): responseStatus --> " & responseStatus)
            End If
            'myResponseStream = response.GetResponseStream()
            If IsDebugOn() Then
                LogDebug("Send_JSON_Request(): got response stream")
            End If

            If Not responseStream Is Nothing Then
                Dim reader As New StreamReader(responseStream)
                If Not reader Is Nothing Then
                    theResponse = reader.ReadToEnd()
                    reader.Close()
                    reader.Dispose()
                    reader = Nothing
                End If
            End If