本人新手,最近在测试post,下面是测试成功的语句,只需要修改传入内容和webservice地址就行了
Dim xmlRequest As String = e.Form.Controls("TextBox2").text ----post传入的内容
Dim xml As String = xmlRequest '实例化一个字符转码对象'
Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
'创建一个web请求对象'
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create("http://192.168.1.18:5566/services/RouteService?wsdl") ----webservice地址
'设置请求方式为post'
request.Method = "POST"
'定义字节数组'
Dim postdata() As System.Byte = encoding.GetBytes(xmlRequest)
'设置request对象的请求字节的长度'
request.ContentLength = postdata.Length
'获取request对象的数据流'
Dim requesstream As System.IO.Stream = request.GetRequestStream()
'将数据内容填充到流中'
requesstream.Write(postdata, 0, postdata.Length)
'关闭流'
requesstream.Close()
'根据请求的request对象获取响应的response对象'
Dim response As System.Net.WebResponse = request.GetResponse()
'获取response数据流对象'
Dim responsestream As New System.IO.StreamReader(response.GetResponseStream())
'将response流中的数据读取'
Dim html As String = responsestream.ReadToEnd()
requesstream.Close()
response.Close()
'返回本次请求的响应数据'
e.Form.Controls("TextBox3").text=html ----post传出内容