How do I authenticate a WebClient request?

后端 未结 4 795
甜味超标
甜味超标 2020-11-28 08:28

I am making a call to a page on my site using webclient. I\'m trying to get the result of the webpage put into a pdf so I am trying to get a string representation of the ren

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 09:17

    Public Function getWeb(ByRef sURL As String) As String
        Dim myWebClient As New System.Net.WebClient()
    
        Try
            Dim myCredentialCache As New System.Net.CredentialCache()
            Dim myURI As New Uri(sURL)
            myCredentialCache.Add(myURI, "ntlm", System.Net.CredentialCache.DefaultNetworkCredentials)
            myWebClient.Encoding = System.Text.Encoding.UTF8
            myWebClient.Credentials = myCredentialCache
            Return myWebClient.DownloadString(myURI)
        Catch ex As Exception
            Return "Exception " & ex.ToString()
        End Try
    End Function
    

提交回复
热议问题