1

我需要通过最前沿的端点请求 Web 服务。我使用基本身份验证。如果我使用此代码,它会完美运行:

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 响应,然后发送了身份验证,我收到了响应。

如果我使用 SoapHttpClientProtocol,我有一个 302 响应,我现在不知道如何处理这个问题。你可以帮帮我吗。

4

1 回答 1

1

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

于 2013-07-08T06:50:07.517 回答