HTTP request from a C# desktop application to a Siteminder-protected server

后端 未结 2 1139
礼貌的吻别
礼貌的吻别 2021-02-19 14:49

I have developed a C# desktop application which makes HTTPS requests to the customers\' servers (usually Documentum/SharePoint/Alfresco/Nem

2条回答
  •  时光说笑
    2021-02-19 15:43

    Same idea as Mohit's answer, but it can be done with a much simpler code:

            //Make initial request for SM to give you some cookies and the authentication URI
            RestClient client = new RestClient("http://theResourceDomain/myApp");
            client.CookieContainer = new CookieContainer();
            IRestResponse response = client.Get(new RestRequest("someProduct/orders"));
    
            //Now add credentials.
            client.Authenticator = new HttpBasicAuthenticator("username", "password");
            //Get resource from the SiteMinder URI which will redirect back to the API URI upon authentication.
            response = client.Get(new RestRequest(response.ResponseUri)); 
    
    • Although this uses RestSharp, it can be easily replicated using HttpClient or even HttpWebRequest.

提交回复
热议问题