首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SoapHttpClientProtocol进行身份验证

使用SoapHttpClientProtocol进行身份验证
EN

Stack Overflow用户
提问于 2013-07-07 22:09:13
回答 1查看 4K关注 0票数 1

我需要通过forefront端点请求need服务。我使用基本身份验证。如果我使用下面的代码,它就能完美地工作:

代码语言:javascript
复制
Uri uri = new Uri("https://ged.legrandnarbonne.com/_vti_bin/webs.asmx");
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

        System.Net.CredentialCache credentialCache = new System.Net.CredentialCache();
        credentialCache.Add(
            new System.Uri("https://xxx.com"),
            "Basic",
            new System.Net.NetworkCredential("xxx", "xxxx")
        );
        string postData = @"<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><GetWeb xmlns='http://schemas.microsoft.com/sharepoint/soap/'><webUrl>https://ged.legrandnarbonne.com</webUrl></GetWeb></soap:Body></soap:Envelope>";
        byte[] byteArray = Encoding.UTF8.GetBytes (postData);
        request.ContentType = "text/xml; charset=utf-8";

        request.Credentials=credentialCache;
        request.Method = "POST";
        request.ContentLength=byteArray.Length;
        Stream dataStream = request.GetRequestStream ();
        dataStream.Write (byteArray, 0, byteArray.Length);
        dataStream.Close ();

        WebResponse v = request.GetResponse();
        Stream rStream = v.GetResponseStream();
        StreamReader str = new StreamReader(rStream);
        if (str.EndOfStream != true)
        {
            Console.WriteLine(str.ReadToEnd());
        }
        v.Close();
        rStream.Close();
        str.Close();

我得到了一个401响应,然后身份验证是send,我得到了响应。

如果我使用SoapHttpClientProtocol,我会得到一个302的响应,我现在不知道如何处理这个问题。你能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2013-07-08 14:50:08

经过长时间的调查,看起来重定向是由于"useragent“头造成的。如果设置了TMG,则发送302将请求重定向到登录页面。如果将其留空,则它可以完美地工作。希望这能对某些人有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17512858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档