http学习

接口:  http://www.kuaidi100.com/query?type=快递公司编码&postid=物流单号

URL:http://www.kuaidi100.com

目标文件地址:query?

参数:type=快递公司编码&postid=物流单号

POST请求:  http://www.kuaidi100.com/query?         流传输:  type=快递公司编码&postid=物流单号

GET请求:http://www.kuaidi100.com/query?type=快递公司编码&postid=物流单号

222

 

https://mock.mengxuegu.com/login  模拟客户服务器自定义返回报文

 

 

 ''' <summary>
    ''' 谢工提供POST请求函数
    ''' </summary>
    ''' <param name="url"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function HttpPostRequest(url As String, SendData As String) As String
        Dim encoding__1 As Encoding = Encoding.UTF8
        ' 请求api地址  
        Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
        'Accept属于http请求头,描述客户端希望接收的响应body 数据类型。就是希望服务器返回什么类型的数据
        'request.Accept = "text/html,application/xhtml+xml,*/*"
        request.Accept = "application/json"
        'Content-Type(内容类型),一般是指网页中存在的 Content-Type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件,这就是经常看到一些 PHP 网页点击的结果却是下载一个文件或一张图片的原因。
        'Content-Type 标头告诉客户端实际返回的内容的内容类型。
        'request.ContentType = "application/json"
        request.ContentType = "application/x-www-form-urlencoded"   '此格式可以反序列化

        request.Method = "POST"

        Dim buffer As Byte() = encoding__1.GetBytes(SendData)
        request.ContentLength = buffer.Length
        request.GetRequestStream().Write(buffer, 0, buffer.Length)

        Try
            Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

            Using reader As New StreamReader(response.GetResponseStream(), Encoding.UTF8)
                Return reader.ReadToEnd()
            End Using
        Catch
            Return ""
        End Try
    End Function

 

posted @ 2022-03-30 10:03  浅物  阅读(42)  评论(0)    收藏  举报