C# 使用 HTTPS 和 httpWebRequest
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10389808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using HTTPS and httpWebRequest
提问by TheGateKeeper
I am sending httpwebrequests to the paypal api server and this uses https. I did the normal things that you normally do with http requests, and it worked. Do I need to do anything special to properly use https, or is specifying https in the request URL enaugh to make it work?
我将 httpwebrequests 发送到 paypal api 服务器,这使用 https。我做了你通常对 http 请求做的正常事情,它奏效了。我需要做任何特殊的事情才能正确使用 https,还是在请求 URL 中指定 https 才能使其正常工作?
Thanks!
谢谢!
Btw my requests are being sent from my server, so it isn't as important to encrypt them as if they where being sent from the client computer, but still I want to do it right.
顺便说一句,我的请求是从我的服务器发送的,所以加密它们并不像从客户端计算机发送它们那样重要,但我仍然想正确地做。
采纳答案by Teoman Soygul
Simply swapping http with https is fine enough while using HttpWebRequest. It requires no special handling for https requests.
使用HttpWebRequest. 它不需要对 https 请求进行特殊处理。
回答by smurtagh
Changing the URL to https shouldbe enough provided that there are no issues with the certificate.
更改URL为https应该足够提供有与证书没有问题。
SSL will check for 3 things when it comes to certificates:
在证书方面,SSL 将检查 3 件事:
- The cert was issued to the URI that you are hitting
- The cert is not expired
- The cert was issued by a trusted authority (e.g.: Verisign)
- 证书已颁发给您正在访问的 URI
- 证书未过期
- 证书由受信任的机构颁发(例如:Verisign)
Of these criteria, #3 is the most commonly failed check. You can programatically ignore any or all of these errors (at your own risk). Hereis an example on how to do that.
在这些标准中,#3 是最常失败的检查。您可以以编程方式忽略任何或所有这些错误(风险自负)。这是有关如何执行此操作的示例。
That said, if this is for the Paypal api, you should not have any certificate errors.
也就是说,如果这是针对 Paypal api,则您不应该有任何证书错误。
回答by ngochoaitn
Work with https if you use method SetCookies(Uri, string)of CookieContainerclass server will reject your request!
To use cookie after login you must use single cookie object!
如果您使用类服务器的方法SetCookies(Uri, string),则使用 httpsCookieContainer将拒绝您的请求!要在登录后使用 cookie,您必须使用单个 cookie 对象!

