使用GET方法向XML页面发送和接收XML数据 [英] Send and receive XML data to asp page using GET method

查看:155
本文介绍了使用GET方法向XML页面发送和接收XML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在编写一个VB .Net Exe,它要求将XML数据发送到ASP URL并捕获响应(也将采用XML格式).

以下是我的代码段(无效):

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):

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


错误在以下行引发:rs.Write(data,0,data.Length)
它说内容主体不能使用这种动词类型发送.

我需要在几天之内完成这项工作.任何帮助将不胜感激.


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.

推荐答案

可以尝试用方法="POST"代替"GET"

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

wr = System.Net.WebRequest.Create(url)
wr.Method = "POST"
wr.ContentLength = Len(sData)


这篇关于使用GET方法向XML页面发送和接收XML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆