none
WinForm程序进行HTTP访问 RRS feed

  • 问题

  • 包含HTTP POST和HTTP GET

    有以下代码:

    Public Class HTTP
    
     Shared Function HttpPOST(ByVal Url As String, ByVal PostData As String, Optional ByVal Time As Integer = 0) As Stream
    
      Dim req As HttpWebRequest
    
      If Time <> 0 Then
    
       req.Timeout = Time
    
      End If
    
      req = WebRequest.Create(Url)
    
      req.Method = "POST"
    
      Dim bytesData() As Byte = System.Text.Encoding.Default.GetBytes(PostData)
    
      req.ContentLength = bytesData.Length
    
      Dim postStream As Stream = req.GetRequestStream()
    
      postStream.Write(bytesData, 0, bytesData.Length)
    
      Dim res As HttpWebResponse = req.GetResponse()
    
      Return res.GetResponseStream
    
     End Function 'POST请求.
    
     Shared Function HttpGET(ByVal Url As String, Optional ByVal Time As Integer = 0) As Stream
    
      Dim req As System.Net.HttpWebRequest
    
      req = WebRequest.Create(Url)
    
      If Time <> 0 Then
    
       req.Timeout = Time
    
      End If
    
      Dim res As System.Net.HttpWebResponse
    
      req.Method = "GET"
    
      res = req.GetResponse()
    
      Return res.GetResponseStream
    
     End Function 'GET请求.
    
    End Class 'HTTP访问类.
    
    

    得到的结果和抓包结果死活不一样.

    求解决方法.


    我是包子!
    2010年8月5日 4:54

答案

全部回复