0
我需要通過前端端點請求web服務。我使用基本身份驗證。它使用這個代碼完美:使用SoapHttpClientProtocol進行身份驗證
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響應,我現在不怎麼處理這個。你可以幫幫我嗎。