tags:

views:

150

answers:

3

I have an application in C# that utilizes Winhttp to make web requests. Is there a way to specify which network card WinHTTP must utilize for its connections?

A: 

WinHTTP is at the wrong spot on the OSI model to deal with hardware level stuff like that. You're going to want to look at modifying the routing table instead.

lod3n
can you elaborate a little more on the routing tables?
webly
Routing can't be properly explained in 600 characters. Google "Route Add". It's low level, and can take your system offline if used carelessly.
lod3n
A: 

There is no publically available option for WinHTTP or WinInet to do Interface Affinity. It appears to be supported in System.Net via the BindIPEndPointDelegate on the Request's ServicePoint.

I am curious what the scenario is to force a specific interface since it points to a problem in the rest of the stack to need such a thing.

Doubt
A: 

I need the same thing!! I am writing an application that needs to determine the Internet state of each adapter on the computer (i.e. is it connected to the Internet or not). So when I issue HttpWebRequest to test for a connection, I need it to use a specific adapter.

I have used BindIPEndPointDelegate to bind to a local IP address matching the adapter I want to use. It works, most of the time, but it also fails sometimes, calling the delegate function endlessly. Other times, I get the exception "The requested address is not valid in its context". I don't know why this happens sometimes, but am doing some more experimentation.