웹 API를 호출하는 기능이 있습니다. TestCallingRemotely
이 [AllowAnonymous]
으로 설정된 경우 제대로 작동합니다.HttpWebRequest를 통한 웹 API 권한 부여
var httpWebRequest = (HttpWebRequest)WebRequest.Create(
"http://localhost/api/services/myApp/commonLookup/TestCallingRemotely");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) {
string input = "{}";
streamWriter.Write(input);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
어떻게 권한 부여를 위해 HttpWebRequest
에 username
및 password
통과합니까?
내 웹 API를 System.Net
만 지원하는 CLR 통합에서 호출해야합니다. 서버가 기본 인증을 사용하는 경우
효과가있었습니다. 형제 님 감사합니다! –
당신을 진심으로 환영합니다! – aaron
안녕하세요, 이제 다른 도메인에서 API에 액세스하려고합니다. CORS를 사용할 수 있도록 [이 해결책] (https://github.com/aspnetboilerplate/aspnetboilerplate-samples/blob/master/SimpleTaskSystem/SimpleTaskSystem.WebSpaAngular/App_Start/SimpleTaskSystemWebModule.cs)을 사용했지만 작동하지 않았습니다. –