VB 进行Post提交。第一次就提交成功。但是第二次给我返回的值是"{}"为空的。大佬看看我的请求代码吧?

c_Miss_nian 2019-05-25 06:04:07
Public Function MyPost() As Boolean
'Dim list As List(Of GetIP) = JsonConvert.DeserializeObject(Of List(Of GetIP))(jo("data").ToString())
'Dim ip As String = list(0).ip
'Dim port As Integer = list(0).port
Dim HttpUrl As New System.Uri(Url)
Try
httpReq = CType(WebRequest.Create(HttpUrl), HttpWebRequest)
httpReq.Timeout = Timeout '服务器超时时间
httpReq.CookieContainer = MyCookies
httpReq.Method = "POST"
If ref <> "" Then
httpReq.Referer = ref
ref = ""
End If
httpReq.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*"
Dim bytesData() As Byte
httpReq.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
bytesData = System.Text.Encoding.ASCII.GetBytes(PostData)
httpReq.Headers.Add("Accept-Language", "zh-cn")
httpReq.Headers.Add("Pragma", "no-cache")
httpReq.Headers.Add("Cache-Control", "no-cache")
httpReq.Headers.Add("X-Requested-With", "XMLHttpRequest")
httpReq.Headers.Add("Upgrade-Insecure-Requests", "1")
httpReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64;) (KHTML,like Gecko) Chrome/73.0.3683.86 safari/537.36"
httpReq.KeepAlive = True
httpReq.ServicePoint.Expect100Continue = False
httpReq.ContentLength = bytesData.Length

Dim postStream As Stream = httpReq.GetRequestStream()
postStream.Write(bytesData, 0, bytesData.Length)
postStream.Close()
httpRes = CType(httpReq.GetResponse(), HttpWebResponse)
sr = New StreamReader(httpRes.GetResponseStream, System.Text.Encoding.GetEncoding(charset))
Html = sr.ReadToEnd()

Return True
Catch WebExcp As WebException
ErrMsg = WebExcp.Message.ToString()
Catch ex As Exception
ErrMsg = ex.Message.ToString()
Finally
Try
If Not sr Is Nothing Then sr.Close()
Catch WebExcp As WebException
Catch ex As Exception
End Try
Try
If Not httpReq Is Nothing Then httpReq.GetRequestStream().Close()
Catch WebExcp As WebException
Catch ex As Exception
End Try
Try
If Not httpRes Is Nothing Then httpRes.GetResponseStream().Close()
Catch WebExcp As WebException
Catch ex As Exception
End Try
End Try
End Function




这个就是完整的post请求的方法。那位大佬帮忙看看。。
...全文
44 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧