我需要通过最前沿的端点请求 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 响应,我现在不知道如何处理这个问题。你可以帮帮我吗。