以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]这个API的接口文件怎么写呢?谢谢!!  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=173559)

--  作者:machle
--  发布时间:2021/12/6 0:47:00
--  [求助]这个API的接口文件怎么写呢?谢谢!!
想问您这个接口文件该怎么写。谢谢!
Class SurroundingClass
    Private Const host As String = "https://generalpdf.market.alicloudapi.com"
    Private Const path As String = "/ocrservice/pdf"
    Private Const method As String = "POST"
    Private Const appcode As String = "你自己的AppCode"

    Private Shared Sub Main(ByVal args As String())
        Dim querys As String = ""
        Dim bodys As String = "{//文件数据:base64编码,要求base64编码后大小不超过100M,页数不超过20页,和url参数只能同时存在一个""fileBase64"":"""",//文件url地址:完整URL,URL长度不超过1024字节,URL对应的文件base64编码后大小不超过100M,页数不超过20页,和img参数只能同时存在一个""url"":"""",//是否需要识别结果中每一行的置信度,默认不需要。true:需要false:不需要""prob"":false,//是否需要单字识别功能,默认不需要。true:需要false:不需要""charInfo"":false,//是否需要自动旋转功能,默认不需要。true:需要false:不需要""rotate"":false,//是否需要表格识别功能,默认不需要。true:需要false:不需要""table"":false,//转文件类型,word""fileType"":""word""}"
        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)
        httpRequest.C

        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
[此贴子已经被作者于2021/12/6 0:58:29编辑过]

--  作者:有点蓝
--  发布时间:2021/12/6 8:55:00
--  
Private Shared Sub Main(ByVal args As String())
改为
public Shared Sub Main(ByVal args As String())

然后转换为vb代码:http://converter.telerik.com/,放到全局代码使用即可