string GetRestAccessToken(string endPoint, string requestName) { try { string EndPointURL = WebServiceRequestData.GetRESTServiceURI(requestName, endPoint); HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(EndPointURL); WebReq.ContentType = "application/x-www-form-urlencoded"; WebReq.Accept = "*/*"; //WebReq.ContinueTimeout = 120000; //WebReq.ContentLength = "Length"; WebReq.Method = "token"; WebReq.Timeout = Timeout.Infinite; WebReq.KeepAlive = true; //WebClient client = new WebClient(); //client.Credentials = new NetworkCredential("bandars1", "Datalabs123", "EDCDEV"); WebReq.Credentials = new NetworkCredential("testadmin", "Datalabs1234", "EDCDEV"); using (StreamWriter writer = new StreamWriter(WebReq.GetRequestStream())) { string body = "Username=pabbatc&Password=Datalabs123&grant_type=password"; writer.WriteLine(body); } WebResponse Response = WebReq.GetResponse(); } catch (Exception e) { new DebugLogGenerator().WriteException(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, e); } return(null); }
public HttpWebRequest BuildGetRestRequest() { try { string accessToken = GetRestAccessToken(EndPoint, RequestName); string EndPointURL = WebServiceRequestData.GetRESTServiceURI(RequestName, EndPoint); HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(EndPointURL); WebReq.Accept = "*/*"; //WebReq.Method = HttpMethod; //WebReq.ContentType = "application/json; charset=utf-8"; WebReq.Headers.Set("Authorization", "Bearer " + accessToken); return(WebReq); } catch (ArgumentNullException e) { new DebugLogGenerator().WriteException(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, e); } catch (Exception e) { new DebugLogGenerator().WriteException(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, e); } return(null); }