Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted (edited)

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."}

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

Edited by PlausiblyDamp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...