Web APIを呼び出す関数があります。 TestCallingRemotely
が[AllowAnonymous]
に設定されているとうまくいきます。私が認可のためHttpWebRequest
からusername
とpassword
を渡すにはどうすればよいHttpWebRequestによるWeb 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();
?
System.Net
のみをサポートするCLR統合からWeb APIを呼び出す必要があります。サーバーが基本認証を使用する場合は
ありがとう! –
よろしくお願いします! – aaron
こんにちは、私は別のドメインからAPIにアクセスしようとしました。私はCORSを有効にするために[このソリューション](https://github.com/aspnetboilerplate/aspnetboilerplate-samples/blob/master/SimpleTaskSystem/SimpleTaskSystem.WebSpaAngular/App_Start/SimpleTaskSystemWebModule.cs)を使用しましたが、動作しませんでした。 –