Reputation:
I need to set the port of a HttpRequest. This is the port the Request is coming FROM.
Normal HTTP scenario:
Request: 127.0.0.1:6745 --> www.stackoverflow.com Response: 1227.0.0.1:6745 <-- www.stackoverflow.com
Request: 127.0.0.1:8096 --> www.stackoverflow.com Response: 1227.0.0.1:8096 <-- www.stackoverflow.com
My scenario:
Request: 127.0.0.1:6745 --> www.stackoverflow.com Response: 1227.0.0.1:6745 <-- www.stackoverflow.com
Request: 127.0.0.1:6745 --> www.stackoverflow.com Response: 1227.0.0.1:6745 <-- www.stackoverflow.com
The request must always come from a defined port. Is this even possible in the HTTP protocol? If yes, how do I use the WebRequest class in the .NEt framework? Or do I have to use manual sockets?
Upvotes: 0
Views: 4845
Reputation: 101130
Switch to a WebClient
instead of HttpWebRequest
since it should keep the connection alive for a period of time.
Do note that HTTP was not built to keep connections open. The connection will always be closed after a a period of idle time.
Upvotes: 0
Reputation: 1038710
What do you mean by requesting port? If it is the temporary port assigned by the OS I don't think that you have any control over it with WebRequest. IMHO it would be better to leave this management to the operating system or you could run into some conflicts with other applications.
Upvotes: 1