1

I am trying to post data in JSON form to a web site, but no matter what I do, I get a 500 Internal Error.

The string I aim to create is something like that : {"orders":[{"id":"7","invoice_number":"1007"},{"id":"8","invoice_number":"1008"},{"id":"11","invoice_number":"1011"}]} , which I can easily get with JSON.net

The webmaster of the site sent me this command in order to post data

curl -vvvvvvvv "http://staging.voltige2001.net/fr/api/update-orders" --data '{"orders":[{"id":"7","invoice_number":"1007"},{"id":"8","invoice_number":"1008"},{"id":"11","invoice_number":"1011"}]}' -X PATCH

But I don't know what is curl and how this differs from what I am doing.

Here is the code I have :

    Dim strInvNumber As String

    If Not IsNothing(oDsFacture) AndAlso oDsFacture.Tables.Count > 0 AndAlso oDsFacture.Tables(0).Rows.Count > 0 Then
        strInvNumber = oDsFacture.Tables(0).Rows(0)("No_Facture")
    Else
        strInvNumber = "9999" ' Pas de facture
    End If

    Dim oOrder As New Confirmation.Order With {.ID = oCommande.ID, .InvoiceNumber = strInvNumber}

    Dim oConfirmation As New Confirmation With {.Orders = New List(Of Confirmation.Order) From {oOrder}}
    Dim strResponse As String = JsonConvert.SerializeObject(oConfirmation)

    Dim data = Encoding.UTF8.GetBytes(strResponse)


    Dim req As WebRequest = WebRequest.Create(_ResponseURL)
    req.ContentType = "application/json"
    req.Method = "POST"
    'req.ContentLength = strResponse.Length

    Using oStream As New StreamWriter(req.GetRequestStream)
        oStream.Write(strResponse)
        oStream.Flush()
        oStream.Close()
    End Using

    Try
        Dim response As HttpWebResponse = req.GetResponse
        Using oSReader As New StreamReader(response.GetResponseStream)

        End Using
    Catch ex As Exception

    End Try

Here is the class I use to convert to JSON

Public Class Confirmation


Public Class Order
    <JsonProperty("id")> Public Property ID As String
    <JsonProperty("invoice_number")> Public Property InvoiceNumber As String
        End Class

<JsonProperty("orders")> Public Property Orders As List(Of Order)
End Class
0

1 Answer 1

1

curl is a command-line tool to transfer network data. Here's the man page: man.cx/curl.

The -X option in the curl example you were given means to use something other than GET. In this case, they are expecting PATCH. Try req.Method = PATCH.

I haven't run into the PATCH method before, the RFC summary makes it sound like an HTTP upsert:

The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request- URI. The set of changes is represented in a format called a "patch document" identified by a media type. If the Request-URI does not point to an existing resource, the server MAY create a new resource, depending on the patch document type (whether it can logically modify a null resource) and permissions, etc.

Sign up to request clarification or add additional context in comments.

1 Comment

That's probably it. I get another error now, but it seems more like a firewall that is posing problem, which is none of my concern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.