在 VB.Net 中通过 SSL 调用 SharePoint Web 服务(401 未经授权)

发布于 2024-09-27 16:11:04 字数 1269 浏览 7 评论 0原文

我正在尝试调用 Lists.asmx SharePoint Web 服务的 AddAttachment,如果我通过 HTTP 调用 Web 服务,下面的代码可以正常工作。

        Dim img(MyFile.PostedFile.ContentLength - 1) As Byte
        MyFile.PostedFile.InputStream.Read(img, 0, img.Length)

        'Dim fStream As FileStream = File.OpenRead(FullFileName)
        Dim fileName As String = MyFile.PostedFile.FileName.Substring(3)

        Dim listService As New wsList.Lists()
        Dim credentials As New System.Net.NetworkCredential(UserName, Password, Domain)

        If Not SiteUrl.EndsWith("/") Then
            SiteUrl += "/"
        End If
        SiteUrl += "_vti_bin/Lists.asmx"
        'SiteUrl = SiteUrl.ToLower.Replace("http:", "https:")

        listService.Url = SiteUrl
        listService.Credentials = credentials

        Dim addAttach As String = listService.AddAttachment(ListName, ItemId, fileName, img)

        ReturnValue = True

但是,如果我取消注释掉这一行,

'SiteUrl = SiteUrl.ToLower.Replace("http:", "https:")

我将收到以下错误: 请求失败,HTTP 状态 401:未经授权

现在,如果我将上面的行注释掉,然后也注释掉这一行,

listService.Credentials = credentials

我将得到相同的 401 错误(预期),因此看来凭证是通过 HTTP 而不是 HTTPS 正确接受的。有人可以帮我解释一下这一点并对如何解决这个问题有什么想法吗?

提前致谢!

I'm trying to call the AddAttachment of the Lists.asmx SharePoint web service the below code works fine if I'm calling the web service over HTTP.

        Dim img(MyFile.PostedFile.ContentLength - 1) As Byte
        MyFile.PostedFile.InputStream.Read(img, 0, img.Length)

        'Dim fStream As FileStream = File.OpenRead(FullFileName)
        Dim fileName As String = MyFile.PostedFile.FileName.Substring(3)

        Dim listService As New wsList.Lists()
        Dim credentials As New System.Net.NetworkCredential(UserName, Password, Domain)

        If Not SiteUrl.EndsWith("/") Then
            SiteUrl += "/"
        End If
        SiteUrl += "_vti_bin/Lists.asmx"
        'SiteUrl = SiteUrl.ToLower.Replace("http:", "https:")

        listService.Url = SiteUrl
        listService.Credentials = credentials

        Dim addAttach As String = listService.AddAttachment(ListName, ItemId, fileName, img)

        ReturnValue = True

However if I uncomment out this line

'SiteUrl = SiteUrl.ToLower.Replace("http:", "https:")

I will get the following error: The request failed with HTTP status 401: Unauthorized

Now if I leave the above line commented out AND then also comment out this line

listService.Credentials = credentials

I will get the same 401 error (expected) so it appears the credentials are being accepted correctly over HTTP but not HTTPS. Can one help explain this to me and have any thoughts on how to fix the issue?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2024-10-04 16:11:04

今天早上我正在和我们的一位系统人员一起工作。他检查了一些 IIS 日志,发现尝试通过 HTTPS 访问 Web 服务时出现错误。他进入中央管理并添加了一些备用访问映射以包含 HTTPS url。然后一切就都成功了!

This morning I was working with one of our system guys. He checked some IIS logs and could see errors trying to access the web service over HTTPS. He went into Central Admin and added some Alternate Access Mappings to include the HTTPS urls. Then everything worked!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文