将JSON POST到端点的麻烦

时间:2017-07-05 21:33:03

标签: vb.net

我正在尝试向给定端点提交包含JSON的POST请求。但是,以下代码将我发送到登录页面,该页面是所有非/ api端点的默认功能。因为Postman没有将我引导到登录页面但是正确地命中了API,我假设问题出现在这个C#代码中。

    Dim RemoteUrl As String = "https://my-site.com/api/tournament/results"
    Dim result As String = ""
    Dim xmlHttpReq As HttpWebRequest = CType(WebRequest.Create(RemoteUrl), HttpWebRequest)
    xmlHttpReq.Method = "POST"
    xmlHttpReq.ContentType = "application/json"

    With (New StreamWriter(xmlHttpReq.GetRequestStream))

         .Write(Json)
         .Flush()
         .Close()

Dim httpResponse As HttpWebResponse = CType(xmlHttpReq.GetResponse(), HttpWebResponse)
    With (New StreamReader(httpResponse.GetResponseStream))
       result = .ReadToEnd
    End With
End With

知道我需要采取哪些步骤来调试它?

0 个答案:

没有答案