Foxtable(狐表)用户栏目专家坐堂 → [求助]关于https的问题,请问以下代码狐表中怎么写?


  共有1650人关注过本帖树形打印复制链接

主题:[求助]关于https的问题,请问以下代码狐表中怎么写?

帅哥哟,离线,有人找我吗?
km007
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:5761 威望:0 精华:0 注册:2016/1/28 2:59:00
[求助]关于https的问题,请问以下代码狐表中怎么写?  发帖心情 Post By:2024/6/30 1:08:00 [显示全部帖子]



        If host.Contains("https://") Then
            ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf CheckValidationResult)  
            httpRequest = CType(WebRequest.CreateDefault(New Uri(url)), HttpWebRequest)
        Else
            httpRequest = CType(WebRequest.Create(url), HttpWebRequest)
        End If


请上上面红色字体的 狐表代码 应该怎么写呢?


[此贴子已经被作者于2024/6/30 21:56:23编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
km007
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:5761 威望:0 精华:0 注册:2016/1/28 2:59:00
  发帖心情 Post By:2024/6/30 21:56:00 [显示全部帖子]

求助 求助

 回到顶部
帅哥哟,离线,有人找我吗?
km007
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:5761 威望:0 精华:0 注册:2016/1/28 2:59:00
  发帖心情 Post By:2024/6/30 23:05:00 [显示全部帖子]

以下是C#转.net后的代码

Class SurroundingClass
    Private Const host As String = "https://ali-deliver.showapi.com"
    Private Const path As String = "/showapi_expInfo"
    Private Const method As String = "GET"
    Private Const appcode As String = "你自己的AppCode"

    Private Shared Sub Main(ByVal args As String())
        Dim querys As String = "com=zhongtong&nu=535962308717&receiverPhone=receiverPhone&senderPhone=senderPhone"
        Dim bodys As String = ""
        Dim url As String = host + path
        Dim httpRequest As HttpWebRequest = Nothing
        Dim httpResponse As HttpWebResponse = Nothing

        If 0 < querys.Length Then
            url = url & "?" + querys
        End If

        If host.Contains("https://") Then
            ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf CheckValidationResult)
            httpRequest = CType(WebRequest.CreateDefault(New Uri(url)), HttpWebRequest)
        Else
            httpRequest = CType(WebRequest.Create(url), HttpWebRequest)
        End If

        httpRequest.Method = method
        httpRequest.Headers.Add("Authorization", "APPCODE " & appcode)

        If 0 < bodys.Length Then
            Dim data As Byte() = Encoding.UTF8.GetBytes(bodys)

            Using stream As Stream = httpRequest.GetRequestStream()
                stream.Write(data, 0, data.Length)
            End Using
        End If

        Try
            httpResponse = CType(httpRequest.GetResponse(), HttpWebResponse)
        Catch ex As WebException
            httpResponse = CType(ex.Response, HttpWebResponse)
        End Try

        Console.WriteLine(httpResponse.StatusCode)
        Console.WriteLine(httpResponse.Method)
        Console.WriteLine(httpResponse.Headers)
        Dim st As Stream = httpResponse.GetResponseStream()
        Dim reader As StreamReader = New StreamReader(st, Encoding.GetEncoding("utf-8"))
        Console.WriteLine(reader.ReadToEnd())
        Console.WriteLine(vbLf)
    End Sub

    Public Shared Function CheckValidationResult(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal errors As SslPolicyErrors) As Boolean
        Return True
    End Function
End Class

 回到顶部
帅哥哟,离线,有人找我吗?
km007
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:5761 威望:0 精华:0 注册:2016/1/28 2:59:00
  发帖心情 Post By:2024/7/1 1:39:00 [显示全部帖子]

但是 这个没有调用sdk的

 回到顶部
帅哥哟,离线,有人找我吗?
km007
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:5761 威望:0 精华:0 注册:2016/1/28 2:59:00
  发帖心情 Post By:2024/7/1 17:43:00 [显示全部帖子]

不是调用SDK才需要设置 命名空间 的吗?


 回到顶部