Settings for web API
- Enable
Windows Authentication
Settings for web application
- Enable
Windows Authentication
- Add
<identity impersonate="true" />
in <system.web>
of web.config
Add the following in the web.config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
Enable Windows Authentication
and ASP.NET Impersonation
within IIS
You can use the following code to POST data to web API (and GET as well obviously)
using (var client = new WebClient { UseDefaultCredentials = true })
{
client.Headers.Add(HttpRequestHeader.ContentType, "application/xml; charset=utf-8");
byte[] responseArray = client.UploadData("URL of web API", "POST", Encoding.UTF8.GetBytes(XMLText));
string response = Encoding.ASCII.GetString(responseArray);
}
NOTE: If you're still getting 401 errors you may need to use an IP address instead of a regular domain name for your URL (e.g.: 155.100.100.10 instead of mycompany.com)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…