vbnet 用webrequest post/get 发送获取消息的例子
httpwebrequest和webrequest差不多。
Public Sub MakeSearch()
Try
Dim Http As Net.HttpWebRequest
Http = DirectCast(System.Net.HttpWebRequest.Create(“网络地址?get参数”), Net.HttpWebRequest)
Http.Method = "GET"
Http.KeepAlive = True
Using Rev As New IO.StreamReader(Http.GetResponse.GetResponseStream, System.Text.Encoding.Default)
MakeSearchHtml = Rev.ReadToEnd
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End SubPublic Sub ShowResult()
Try
Dim Http As Net.HttpWebRequest
Http = DirectCast(System.Net.HttpWebRequest.Create(“post服务器地址”), Net.HttpWebRequest)
Http.Method = "POST"
Http.ContentType = "application/x-www-form-urlencoded"
Http.KeepAlive = True
Using Send As New IO.StreamWriter(Http.GetRequestStream, System.Text.Encoding.Default)
Send.Write(CommandLine)'跟服务器通讯的命令。
Send.Flush()
End Using
Using Rev As New IO.StreamReader(Http.GetResponse.GetResponseStream, System.Text.Encoding.Default)
ShowResultHtml = Rev.ReadToEnd‘返回结果。
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
广告 您可能关注的内容 |