c_Miss_nian 2019-05-25 18:01 采纳率: 0%
浏览 442

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

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
  • 写回答

1条回答 默认 最新

  • threenewbee 2019-05-26 08:19
    关注

    在浏览器里操作是否报错,然后用浏览器的F12抓包,和你的程序也抓包做对比,看有什么不同
    特别注意cookie和post的数据,另外看下服务器是不是有反爬机制,比如频繁提交会被限制等等。

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退