Click here to Skip to main content
15,902,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am writing a VB .Net Exe which requires to send XML data to an ASP url and catch the response (which will also be in XML format).

The following is my snippet (which doesn't work):
VB
Try
    With xmlDoc
        xmlRoot = .CreateElement("TXN")
        xmlRoot.AppendChild(.CreateElement("HDR"))
        xmlRoot.SelectSingleNode("HDR").AppendChild(.CreateElement("ID"))
        xmlRoot.SelectSingleNode("HDR").SelectSingleNode("ID").AppendChild(.CreateTextNode("ABCDE"))
        .AppendChild(xmlRoot)
    End With
    data = System.Text.Encoding.UTF8.GetBytes(xmlDoc.OuterXml)
    sData = New System.Text.UTF8Encoding().GetString(data)
    wr = System.Net.WebRequest.Create(url)
    wr.Method = "GET"
    wr.ContentLength = Len(sData)
    rs = wr.GetRequestStream()
    rs.Write(data, 0, data.Length)
    rs.Close()
    wr2 = wr.GetResponse()
    sr = wr2.GetResponseStream()
    sr2 = New System.IO.StreamReader(sr)
    Me.TextBox1.Text = Me.TextBox1.Text & sr2.ReadToEnd
Catch x As Exception
    Me.TextBox1.Text = Me.TextBox1.Text & x.Message.ToString() & vbCrLf
End Try

The error is thrown at the line: rs.Write(data, 0, data.Length)
It says that content body cannot be sent with this verb type.

I need to make this work within a couple of days. Any help would be greatly appreciated.
Posted
Updated 20-May-11 5:03am
v3

1 solution

Can you try method = "POST" instead of "GET"

VB
wr = System.Net.WebRequest.Create(url)
wr.Method = "POST"
wr.ContentLength = Len(sData)
 
Share this answer
 
Comments
Member 4291906 20-May-11 8:28am    
That's not an option. The server expects the XML data in the query string.
Sergey Alexandrovich Kryukov 20-May-11 22:09pm    
This answer sounds like a right idea, my 5.

@Member 4291906: what do you mean "not an option"? How is you XML data or what ever related to the request type. This is just a fix of your bug. If you ***send*** data, it's POST. You say "send XML" data and not sending it. How to understand you?
--SA
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900