传递base64字符串时URI太大

时间:2016-10-14 12:56:48

标签: .net json vb.net json.net

我收到错误,http错误414.在尝试将base64字符串传递给webservice时,请求url太长了。我已经在多个论坛中看到我应该使用POST来传输数据,但我找不到任何似乎对我有用的示例。

以下是我收到错误的示例代码。

Dim syncClient = New WebClient()

Dim url As String = "https://login.someurl.com=" & vin & "&action=attachdoc&transaction_id" & transactionID & "&filename=" & filename & "&docdata="

Dim jsonstring As String = syncClient.UploadString(url, base64String)
Dim node As XNode = JsonConvert.DeserializeXNode(jsonstring, "Results")
Return node.ToString

我也试过下面的POST示例代码而没有运气。给出了相同的URI错误。

   ' Create a request using a URL that can receive a post. 
    Dim request As WebRequest = WebRequest.Create(url)
    ' Set the Method property of the request to POST.
    request.Method = "POST"
    ' Create POST data and convert it to a byte array.
    Dim postData As String = base64String
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
    ' Set the ContentType property of the WebRequest.
    request.ContentType = "application/json"
    ' Set the ContentLength property of the WebRequest.
    request.ContentLength = byteArray.Length
    ' Get the request stream.
    Dim dataStream As Stream = request.GetRequestStream()
    ' Write the data to the request stream.
    dataStream.Write(byteArray, 0, byteArray.Length)
    ' Close the Stream object.
    dataStream.Close()
    ' Get the response.
    Dim response As WebResponse = request.GetResponse()
    ' Display the status.
    Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
    ' Get the stream containing content returned by the server.
    dataStream = response.GetResponseStream()
    ' Open the stream using a StreamReader for easy access.
    Dim reader As New StreamReader(dataStream)
    ' Read the content.
    Dim responseFromServer As String = reader.ReadToEnd()
    ' Display the content.
    Console.WriteLine(responseFromServer)
    ' Clean up the streams.
    reader.Close()
    dataStream.Close()
    response.Close()

0 个答案:

没有答案