locked
How can i add WebProxy to a Rest request? RRS feed

  • Question

  • User1253338400 posted

    If i have a rest request for example:           

    var client = new RestClient(url);         

    var request = new RestRequest { Method = Method.GET, Resource = $"v2/userdetails" };           

    request.AddHeader("Authorization", $"Bearer {token}");           

    var response = client.Execute(request);           

    if (response.StatusCode == HttpStatusCode.OK)             

      return JsonConvert.DeserializeObject<List<UserDetails>>(response.Content);           

    return null;

    How can i pass WebProxy details into the RestClient  so if authenticated then they will get the returned data ?

    thanks

    Thursday, April 15, 2021 8:06 AM

All replies

  • User503812343 posted

    your service is written in WCF or Web API. 

    rest service with json object

      private static void GetOrderDetails(string orderID)
            {
                WebClient proxy = new WebClient();
                string serviceURL = 
                        string.Format("http://localhost:61090/OrderService.svc
                                        /GetOrderDetails/{0}", orderID); 
                byte[] data = proxy.DownloadData(serviceURL);
                Stream stream = new MemoryStream(data);
                DataContractJsonSerializer obj = 
                            new DataContractJsonSerializer(typeof(OrderContract));
                OrderContract order = obj.ReadObject(stream) as OrderContract;
                Console.WriteLine("Order ID : " + order.OrderID);
                Console.WriteLine("Order Date : " + order.OrderDate);
                Console.WriteLine("Order Shipped Date : " + order.ShippedDate);
                Console.WriteLine("Order Ship Country : " + order.ShipCountry);
                Console.WriteLine("Order Total : " + order.OrderTotal);
            }

    Thursday, April 22, 2021 7:39 AM