Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am learning web services and want to get this client working. I get the error "Cannot send a content-body with this verb-type" You can see I have set the method to "POST". The error comes when I try to execute the line with ws.getRequestStream. Any Ideas? Thanks.

 

Public Class Form1

 

Dim myUrl As String = "http://www.webserviceX.net"

Dim ws As System.Net.HttpWebRequest = System.Net.WebRequest.Create(myUrl)

 

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

 

Try

ws.Host = "www.webserviceX.net"

ws.Method = "POST"

ws.Timeout = 60000

ws.Accept = "text/xml"

ws.Headers.Add("SOAPAction", "http://www.webserviceX.NET/GetBookTitles")

' ws.ClientCertificates.Add

ws.ContentType = "text/xml; charset=""utf-8"""

 

Dim myxml As String = "<?xml version=""1.0"" encoding=""UTF-8""?>" & System.Environment.NewLine & _

"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & System.Environment.NewLine & _

"<soap:Body>" & System.Environment.NewLine & _

"<GetBookTitles xmlns=""http://www.webserviceX.NET"">" & System.Environment.NewLine & _

"</soap:Body>" & System.Environment.NewLine & _

"</soap:Envelope>"

Dim myencoder As New System.Text.ASCIIEncoding()

Dim myxmlByteArray() As Byte = myencoder.GetBytes(myxml)

ws.ContentLength = myxmlByteArray.Length

 

Dim postquerystream As System.IO.Stream = ws.GetRequestStream()

postquerystream.Write(myxmlByteArray, 0, myxmlByteArray.Length)

postquerystream.Close()

Dim response As System.Net.HttpWebResponse = ws.GetResponse()

If response.StatusCode = System.Net.HttpStatusCode.OK Then

Dim respstream As System.IO.StreamReader = New IO.StreamReader(ws.GetRequestStream())

Dim responsedata As String = respstream.ReadToEnd()

Me.TextBox1.Text = responsedata

End If

response.Close()

Catch ex As Exception

Dim x As String = ex.ToString

End Try

End Sub

End Class

Posted

I have corrected this error by changing getRequestStream to getResponseStream but have a new problem. This the http header being sent.

 

POST / HTTP/1.1

Accept: text/xml

SOAPAction: http://www.webserviceX.NET/GetBookTitles

Content-Type: text/xml; charset="utf-8"

Host: http://www.webservicex.net

Content-Length: 207

Expect: 100-continue

Connection: Keep-Alive

 

The request line is not correct. My method is not showing in for the post. I am not sure how to get it there with httpWebRequest

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