狐表的HttpClient请求有个缺陷,必须要用原生的HttpWebRequest
headers里不能添加cookie字样
如果直接用hc.sCookies添加,又会被urlEncode修改
我也发帖在论坛问过了:http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=189049&authorid=0&page=0&star=1
' 创建一个HttpWebRequest对象 Dim request As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create("你的网址"), System.Net.HttpWebRequest) ' 设置请求方法为POST request.Method = "POST" ' 添加自定义头部信息 request.Headers.Add("cookie", "xxx") request.Headers.Add("mallid", "xxx") ' 构建要发送的数据 Dim jo As New JObject jo("pageNo") = 1 jo("pageSize") = 900 jo("urgencyType") = 0 jo("isCustomGoods") = False Dim postData As String = jo.ToString ' 根据你的需要构建 POST 数据 ' 将数据转换为字节数组 Dim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes(postData) ' 设置请求的Content-Type和Content-Length头部信息 request.ContentType = "application/json" request.ContentLength = byteArray.Length ' 获取请求流并将数据写入请求 Dim dataStream As System.IO.Stream = request.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() ' 发送请求并获取响应 Dim response As System.Net.HttpWebResponse = Nothing Try response = DirectCast(request.GetResponse(), System.Net.HttpWebResponse) ' 检查响应状态码是否为 200 If response.StatusCode = 200 Then ' 读取响应数据 Dim responseStream As System.IO.Stream = response.GetResponseStream() Dim reader As New System.IO.StreamReader(responseStream) Dim responseText As String = reader.ReadToEnd() ' 打印响应数据 Output.show("响应数据: " & responseText) End If Catch ex As System.Net.WebException ' 捕获 WebException,可以在此处理其他异常或显示错误消息框 MessageBox.Show("发生异常:" & ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally If response IsNot Nothing Then response.Close() End If End Try