Error posting data to API

Murray Brown
Murray Brown used Ask the Experts™

In my web app.  I am editing data via an API and sometimes
get the error I the image. My code is as follows. I have no idea what this error means

 Public Function PostEmployeeHoursEdit(DataLines As List(Of LineEdit), StoreID As Integer) As String

        Dim Resp As HttpWebResponse
            Dim url As String = ""
            Dim API_Method As String = "EmployeeHours"

            Dim data As String = ""
            data = Newtonsoft.Json.JsonConvert.SerializeObject(DataLines)

            Dim Auth As String = Me.txtUsername.Text & ":" & Me.txtPassword.Text
            Dim webAddress As String = url & API_Method & "/" & StoreID & "/0"
            Dim request As HttpWebRequest = HttpWebRequest.Create(webAddress)
            request.Method = WebRequestMethods.Http.Post
            request.Headers.Add("Authorization", Auth)
            request.ContentType = "application/json"
            request.ContentLength = data.Length

            Dim writer As New StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII)

            Resp = request.GetResponse()
            Dim stream As Stream = request.GetResponse().GetResponseStream()
            Dim reader As New StreamReader(stream)
            Dim response As String = reader.ReadToEnd()

            Return "OK"

        Catch wex As WebException
            Dim response As WebResponse = wex.Response
            Dim statusCode As HttpStatusCode

            Dim httpResponse As HttpWebResponse = CType(response, HttpWebResponse)
            statusCode = httpResponse.StatusCode
            Return statusCode & " " & httpResponse.StatusDescription
        End Try

    End Function

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Add this to Configuration section in web.config:

                      <jsonSerialization maxJsonLength="67000000"/>

If error persist then change :
To write data in blocks of 8k
Murray Developer


Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial