使用JSON.net将JSON数据发布到vb.net中的web服务器



我正试图将JSON形式的数据发布到网站上,但无论我做什么,我都会收到500内部错误。

我想要创建的字符串是这样的:{"orders":[{"id":"7","invoice_number":"1007"},{"id:"8","invoice_number":"1008"},{"id":"11","invoice_nnumber":"1011"}]},我可以通过JSON.net 轻松获得

网站的站长给我发了这个命令,以便发布数据

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

但我不知道什么是旋度,也不知道这和我现在做的有什么不同。

这是我的代码:

    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

这是我用来转换为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

curl是一个用于传输网络数据的命令行工具。这是手册页:man.cx/curl.

在给出的curl示例中,-X选项意味着使用GET以外的东西。在这种情况下,他们期待PATCH。尝试req.Method = PATCH

我以前没有遇到过PATCH方法,RFC摘要让它听起来像一个HTTP错误:

PATCH方法要求将请求实体应用于请求所标识的资源-URI。该组变化以称为"变化"的格式表示;色斑文件";由媒体类型标识。如果请求URI没有则服务器可以创建新的资源,取决于修补程序文档类型(是否可以进行逻辑修改空资源)和权限等。

相关内容

  • 没有找到相关文章

最新更新