我需要通过forefront端点请求need服务。我使用基本身份验证。如果我使用下面的代码,它就能完美地工作:
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的响应,我现在不知道如何处理这个问题。你能帮我吗?
发布于 2013-07-08 14:50:08
经过长时间的调查,看起来重定向是由于"useragent“头造成的。如果设置了TMG,则发送302将请求重定向到登录页面。如果将其留空,则它可以完美地工作。希望这能对某些人有所帮助。
https://stackoverflow.com/questions/17512858
复制相似问题