Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Request through Proxy using RestSharp

I'm trying to make a webrequest through a proxy on Windows phone 7. From what I can see the Compact Framework does not include the configuring of a proxy for the HttpWebRequest object. I tried using RestSharp but the RestClient also does not allow this. I've also tried configuring the Internet Options on my local machine to use a proxy, hopping that the same options will apply on my Windows Phone Emulator. That didn't work. Do you have any ideas?

like image 955
Flaviu Zapca Avatar asked Aug 21 '12 08:08

Flaviu Zapca


People also ask

How do I post a request on RestSharp?

var client = new RestClient("URL"); var request = new RestRequest("Resources",Method. POST); request. RequestFormat = RestSharp. DataFormat.

What is RestSharp used for?

RestSharp is a comprehensive, open-source HTTP client library that works with all kinds of DotNet technologies. It can be used to build robust applications by making it easy to interface with public APIs and quickly access data without the complexity of dealing with raw HTTP requests.


2 Answers

Under "configuration" section in Web.config add this:

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy>
</system.net>

(for more more info - MSDN - defaultProxy Element (Network Settings))

like image 120
Israel Margulies Avatar answered Sep 21 '22 19:09

Israel Margulies


For people coming from Google looking how to set a proxy with RestSharp, if you are not on Windows Phone, at least as of version 104.4.0 you can do the following:

var client = new RestClient("http://example.com")
client.Proxy = new WebProxy("http://proxy.example.com")

Don't know whether this would work on Windows Phone since I am not familiar with the framework there; since the title of the question did not contain Windows Phone I thought that many like myself would end up here, just searching about how to setup the proxy with RestSharp.

like image 33
Stefano Ricciardi Avatar answered Sep 21 '22 19:09

Stefano Ricciardi