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