My web client error:Content-Length or Chunked Encoding cannot be set for an operation

groads2

Newcomer
Joined
May 23, 2012
Messages
16
I am trying to learn how to write a web client. I wrote a WCF web client to the same site in the code below and that worked. I would also like to write one similar to the code below. Any ideas on what I am doing wrong would be great. I am getting the error:
InnerException = {"Content-Length or Chunked Encoding cannot be set for an operation that does not write data."}
Visual Basic:
Public Class Form1
Dim manualWebClient As New System.Net.WebClient()
   Private Sub Jack() Handles Button1.Click
        manualWebClient.Headers.Add("Content-Type", "text/xml;  charset=utf-8")
        manualWebClient.BaseAddress = "http://ws.cdyne.com"
        Dim reqstr As String = "<s11:Envelope xmlns:s11=""http://schemas.xmlsoap.org/soap/envelope/"">" & System.Environment.NewLine & _
            "<s11:Body>" & System.Environment.NewLine & _
            "<ns1:GetCityForecastByZIP xmlns:ns1=""http://ws.cdyne.com/WeatherWS/"">" & System.Environment.NewLine & _
            "<ns1:ZIP>33569</ns1:ZIP>" & System.Environment.NewLine & _
            "</ns1:GetCityForecastByZIP>" & System.Environment.NewLine & _
            "</s11:Body>" & System.Environment.NewLine & _
            "</s11:Envelope>"
        ' manualWebClient.Headers.Add("Content-Length", Len(reqstr).ToString)
        Dim bytArguments As Byte() = System.Text.Encoding.ASCII.GetBytes(reqstr)
        Try
            Dim bytRetData As Byte() = manualWebClient.UploadData("/WeatherWS/Weather.asmx", "POST", bytArguments)
            MessageBox.Show(System.Text.Encoding.ASCII.GetString(bytRetData))
        Catch ex As Exception
            Dim v As String = ex.ToString
        End Try

    End Sub
End Class
 
Last edited by a moderator:
Back
Top