C#

azure

web.comfg
沒有httpRuntime 會返回error 400

<?xml version="1.0"?>
<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.8" />
      <httpRuntime targetFramework="4.8" />
    </system.web>
</configuration>
        using (var client = new WebClient())
        {

            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            var parameters = new System.Collections.Specialized.NameValueCollection();


            parameters["grant_type"] = "client_credentials";
            parameters["client_id"] = "38d4372e-4bd2-4f76-b14a-d099e04c7543";
            parameters["client_secret"] = "key";

            /*
            parameters["grant_type"] = "password";
            parameters["client_id"] = "38d4372e-4bd2-4f76-b14a-d099e04c7543";
            parameters["username"] = "username";
            parameters["password"] = "password";
            */


            //parameters["resource"] = "https://analysis.windows.net/powerbi/api";



            var responseBytes = client.UploadValues("https://login.microsoftonline.com/6cef7734-f1ec-4359-96c4-28ed1b9b0099/oauth2/token", "POST", parameters);
            var response = System.Text.Encoding.UTF8.GetString(responseBytes);
            //var json = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(response);
            //return json["access_token"];
            TextBox1.Text = response;
        }

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。