1

I've downloaded the latest version of RestSharp v107. My local machine has multiple IP addresses. Using an older version of RestSharp, I was able to choose which IP address to use using this code: client.ConfigureWebRequest(req => { req.ServicePoint.BindIPEndPointDelegate = (servicePoint, remoteEndPoint, retryCount) => new IPEndPoint("192.25.25.25", 0); });

I can't seem to figure out how to accomplish this with the new RestSharp. Is it even possible?

I've searched the internet/documentation and explored the intellisense. I couldn't figure any way to change the IP address.

Robert
  • 31
  • 2

1 Answers1

0

yes, it's possible but quite different as RestSharp did a lot breaking changes

The easiest way would be to use a nuget version before the break.

If you want to stay on the new version you have to pass a preconfigured HttpClient to Restsharp's constructor.

I do not want to copy the code from custom public static HttpClient GetHttpClient(IPAddress address) from How to bind HttpClient to a specific (source) ip address in .NET 5.

and use it like var myRestclient = new RestClient(GetHttpClient( IPAddress.Parse("192.168.11.11")));

Refs with deeper info to HttpClients history and IP mapping: https://github.com/bonesoul/dotnet_5_httpclient_rest_bind

Falco Alexander
  • 3,092
  • 2
  • 20
  • 39
  • Atm RestSharp uses `HttpClientHandler` and it seems that to bind to a specific IP one would need to use `SocketsHttpHandler`. Until today I never heard anyone needing this, but it should be possible to add a new configuration function to get a new handler instead of configuring the pre-created handler. – Alexey Zimarev Mar 12 '23 at 18:03
  • It's also possible to pass a message handler instance and RestSharp will create an HttpClient instance with it. However, it would not apply any option that is otherwise used to configure the handler as it will use a pre-created handler. – Alexey Zimarev Mar 12 '23 at 18:04