设置HTTP WebRequest的请求端口
我需要设置 HttpRequest 的端口。这是请求来自的端口。
正常HTTP场景:
请求:127.0.0.1:6745 --> www.stackoverflow.com 响应:1227.0.0.1:6745 <-- www.stackoverflow.com
请求:127.0.0.1:8096 --> www.stackoverflow.com 响应:1227.0.0.1:8096 <-- www.stackoverflow.com
我的场景:
请求:127.0.0.1:6745 --> www.stackoverflow.com 响应:1227.0.0.1:6745 <-- www.stackoverflow.com
请求:127.0.0.1:6745 --> www.stackoverflow.com 响应:1227.0.0.1:6745 <-- www.stackoverflow.com
请求必须始终来自定义的端口。这在 HTTP 协议中可能吗?如果是,如何使用 .NEt 框架中的 WebRequest 类?或者我必须使用手动插座吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请求端口是什么意思?如果它是操作系统分配的临时端口,我认为您无法使用 WebRequest.恕我直言,最好将这种管理留给操作系统,否则您可能会与其他应用程序发生一些冲突。
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.
切换到
WebClient
而不是HttpWebRequest
,因为它应该使连接保持活动一段时间。请注意,HTTP 并不是为了保持连接打开而构建的。连接总是会在一段空闲时间后关闭。
Switch to a
WebClient
instead ofHttpWebRequest
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.