以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]关于https的问题,请问以下代码狐表中怎么写?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=192527)

--  作者:km007
--  发布时间:2024/6/30 1:08:00
--  [求助]关于https的问题,请问以下代码狐表中怎么写?


        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
--  发布时间:2024/6/30 21:56:00
--  
求助 求助
--  作者:有点蓝
--  发布时间:2024/6/30 22:30:00
--  
补上命名空间
Net.ServicePointManager.ServerCertificateValidationCallback = New Net.Security.RemoteCertificateValidationCallback(AddressOf CheckValidationResult)
httpRequest = CType(Net.WebRequest.CreateDefault(New Uri(url)), Net.HttpWebRequest)
[此贴子已经被作者于2024/6/30 22:30:21编辑过]

--  作者:km007
--  发布时间: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

--  作者:有点蓝
--  发布时间:2024/6/30 23:12:00
--  
1、全部补上命名空间
2、所有Private 改为 Public 

--  作者:km007
--  发布时间:2024/7/1 1:39:00
--  
但是 这个没有调用sdk的
--  作者:有点蓝
--  发布时间:2024/7/1 8:26:00
--  
哪有啥问题?
--  作者:km007
--  发布时间:2024/7/1 17:43:00
--  
不是调用SDK才需要设置 命名空间 的吗?


--  作者:有点蓝
--  发布时间:2024/7/1 20:08:00
--  
错误!所有.net的类型都需要命名空间,Foxtable只是使用了.net部分功能,所以并没有把所有.net的dll以及对应的命名空间都引用到Foxtable里,因此需要用到Foxtable没有的功能的时候基本都需要添加对应的命名空间