VB.NET 中的发布请求无法正常工作



我想用我保存在文件中的cookie执行此请求(cookie很好,因为我可以执行其他请求到页面)

http://www.banggood.com/index.php?com=event&t=recordSignInShare&fb_id=197203087314503_251208398580638&code=

是的,最后一个参数应该为空。当我在浏览器中打开它时,它会为我提供JSON数据(无论它们看起来如何)但是,当我尝试在vb.net应用程序上执行相同的请求时,它将我重定向到另一个页面。这是VB的代码:

 Dim postData As String = "com=event&t=recordSignInShare&fb_id=197203087314503_251208398580638&code="
    Dim bytes() As Byte = ASCIIEncoding.UTF8.GetBytes(postData)
    Dim postReq As HttpWebRequest = WebRequest.Create("http://www.banggood.com/index.php")
    postReq.Method = "POST"
    postReq.KeepAlive = True
    postReq.CookieContainer = cookies
    'postReq.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
    postReq.Referer = "http://www.banggood.com/"
    postReq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"
    postReq.ContentLength = bytes.Length
    Dim postStream As Stream = postReq.GetRequestStream()
    postStream.Write(bytes, 0, bytes.Length)
    postStream.Close()
    Dim postResponse As HttpWebResponse
    postResponse = postReq.GetResponse()
    cookies.Add(postResponse.Cookies)
    Dim reader As New StreamReader(postResponse.GetResponseStream())
    Dim strSource As String = reader.ReadToEnd
    Return strSource

它返回我的HTML代码,而不是JSON数据:(

这是我通过浏览器打开网络监视器的外观请求请求:

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate, sdch
Accept-Language:pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Host:www.banggood.com
Referer:http://www.banggood.com/2016midyear.html?utmid=796
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36
X-Requested-With:XMLHttpRequest

响应: cache-control:max-age = 0,无循环,无存储 连接:保持活力 内容长度:94 内容类型:text/html;charset = UTF-8我认为原始的(来自代码)请求/响应标头并不重要,因为我只能通过在浏览器中打开此链接来正确执行它。

问题是,我需要获取请求:p谢谢the_lotus

                Dim urlphp As String = "" & dominio & "" & carpetanoti & "/demanda_alta.php"
                Dim Conexion As HttpWebRequest = CType(WebRequest.Create(urlphp), HttpWebRequest)
                Conexion.Method = "POST"
                Conexion.ContentType = "application/x-www-form-urlencoded"
                Dim POST_DATA As String = ("&cTitulo=" & "Te necesitamos!!" & "&cMensaje=" & "ALTA DEMANDA TENEMOS DOMICILIOS PARA TI" & "")
                Dim byteArray() As Byte = Encoding.UTF8.GetBytes(POST_DATA)
                Conexion.ContentLength = byteArray.Length
                Dim FLUJO As Stream = Conexion.GetRequestStream()
                FLUJO.Write(byteArray, 0, byteArray.Length)
                FLUJO.Close()
                Dim Response As HttpWebResponse = Conexion.GetResponse()
                FLUJO = Response.GetResponseStream()
                Dim LEER As New StreamReader(FLUJO)
                Dim ServerResponse As String = LEER.ReadToEnd()
                LEER.Close()
                FLUJO.Close()
                Response.Close()

相关内容

  • 没有找到相关文章

最新更新