Title: Invoke-WebRequest and Invoke-RestMethod do not support invalid HTTPS certificates · Issue #1945 · PowerShell/PowerShell · GitHub
Open Graph Title: Invoke-WebRequest and Invoke-RestMethod do not support invalid HTTPS certificates · Issue #1945 · PowerShell/PowerShell
X Title: Invoke-WebRequest and Invoke-RestMethod do not support invalid HTTPS certificates · Issue #1945 · PowerShell/PowerShell
Description: On Windows, I was able to connect to HTTPS endpoints with invalid certificates by setting a certificate policy via System.Net.ServicePointManager to ignore invalid certificates. An integrated way to ignore invalid certificates with Invok...
Open Graph Description: On Windows, I was able to connect to HTTPS endpoints with invalid certificates by setting a certificate policy via System.Net.ServicePointManager to ignore invalid certificates. An integrated way t...
X Description: On Windows, I was able to connect to HTTPS endpoints with invalid certificates by setting a certificate policy via System.Net.ServicePointManager to ignore invalid certificates. An integrated way t...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/1945
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invoke-WebRequest and Invoke-RestMethod do not support invalid HTTPS certificates","articleBody":"On Windows, I was able to connect to HTTPS endpoints with invalid certificates by setting a certificate policy via System.Net.ServicePointManager to ignore invalid certificates. \n\nAn integrated way to ignore invalid certificates with `Invoke-RestMethod` and `Invoke-WebMethod` would simplify implementing this cross platform.\n\nWhen I run the same on Mac OS X, I get several errors regarding .NET dependencies. How can Invoke-RestMethod and Invoke-WebMethod be configured to ignore invalid certificates?\n## Steps to reproduce\n\n``` powershell\nadd-type @\"\nusing System.Net;\nusing System.Security.Cryptography.X509Certificates;\npublic class TrustAllCertsPolicy : ICertificatePolicy {\n public bool CheckValidationResult(\n ServicePoint srvPoint, X509Certificate certificate,\n WebRequest request, int certificateProblem) {\n return true;\n }\n }\n\"@\n[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy\nInvoke-WebRequest https://expired.badssl.com/\n```\n## Expected behavior\n\nThis is from Windows Server 2008R2 with PowerShell 5:\n\n``` powershell\nPS C:\\> add-type @\"\n>> using System.Net;\n>> using System.Security.Cryptography.X509Certificates;\n>> public class TrustAllCertsPolicy : ICertificatePolicy {\n>> public bool CheckValidationResult(\n>> ServicePoint srvPoint, X509Certificate certificate,\n>> WebRequest request, int certificateProblem) {\n>> return true;\n>> }\n>> }\n>> \"@\n>>\nPS C:\\> [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy\nPS C:\\> Invoke-WebRequest https://expired.badssl.com/\n\n\nStatusCode : 200\nStatusDescription : OK\nContent : \u003c!DOCTYPE html>\n \u003chtml>\n \u003chead>\n \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n \u003clink rel=\"shortcut icon\" href=\"/icons/favicon-red.ico\"/>\n \u003clink rel=\"apple-touch-icon\" href=\"/i...\nRawContent : HTTP/1.1 200 OK\n Connection: keep-alive\n Accept-Ranges: bytes\n Content-Length: 469\n Cache-Control: no-store\n Content-Type: text/html\n Date: Fri, 19 Aug 2016 08:36:02 GMT\n ETag: \"57b263a4-1d5\"\n Last-Mo...\nForms : {}\nHeaders : {[Connection, keep-alive], [Accept-Ranges, bytes], [Content-Length, 469], [Cache-Control,\n no-store]...}\nImages : {}\nInputFields : {}\nLinks : {}\nParsedHtml : mshtml.HTMLDocumentClass\nRawContentLength : 469\n```\n## Actual behavior\n\n``` powershell\nPS /Users/ffeldhaus> add-type @\" >> using System.Net; >> using System.Security.Cryptography.X509Certificates; >> public class TrustAllCertsPolicy : ICertificatePolicy { >> public bool CheckValidationResult( >> ServicePoint srvPoint, X509Certificate certificate, >> WebRequest request, int certificateProblem) { >> return true; >> } >> } >> \"@ \nadd-type : (2) : The type or namespace name 'X509Certificates' does not exist in the namespace 'System.Security.Cryptography' (are you missing an assembly reference?)\n(1) : using System.Net;\n(2) : >>> using System.Security.Cryptography.X509Certificates;\n(3) : public class TrustAllCertsPolicy : ICertificatePolicy {\nAt line:1 char:13\n+ add-type @\"\n+ ~~~~~~~~~~~\n + CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception\n + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand\n\nadd-type : (3) : The type or namespace name 'ICertificatePolicy' could not be found (are you missing a using directive or an assembly reference?)\n(2) : using System.Security.Cryptography.X509Certificates;\n(3) : >>> public class TrustAllCertsPolicy : ICertificatePolicy {\n(4) : public bool CheckValidationResult(\nAt line:1 char:13\n+ add-type @\"\n+ ~~~~~~~~~~~\n + CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception\n + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand\n\nadd-type : (5) : The type or namespace name 'ServicePoint' could not be found (are you missing a using directive or an assembly reference?)\n(4) : public bool CheckValidationResult(\n(5) : >>> ServicePoint srvPoint, X509Certificate certificate,\n(6) : WebRequest request, int certificateProblem) {\nAt line:1 char:13\n+ add-type @\"\n+ ~~~~~~~~~~~\n + CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception\n + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand\n\nadd-type : (5) : The type or namespace name 'X509Certificate' could not be found (are you missing a using directive or an assembly reference?)\n(4) : public bool CheckValidationResult(\n(5) : >>> ServicePoint srvPoint, X509Certificate certificate,\n(6) : WebRequest request, int certificateProblem) {\nAt line:1 char:13\n+ add-type @\"\n+ ~~~~~~~~~~~\n + CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception\n + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand\n\nadd-type : (6) : The type or namespace name 'WebRequest' could not be found (are you missing a using directive or an assembly reference?)\n(5) : ServicePoint srvPoint, X509Certificate certificate,\n(6) : >>> WebRequest request, int certificateProblem) {\n(7) : return true;\nAt line:1 char:13\n+ add-type @\"\n+ ~~~~~~~~~~~\n + CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception\n + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand\n\nadd-type : Cannot add type. Compilation errors occurred.\nAt line:1 char:13\n+ add-type @\"\n+ ~~~~~~~~~~~\n + CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException\n + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand\nPS /Users/ffeldhaus> [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy \nUnable to find type [System.Net.ServicePointManager].\nAt line:1 char:1\n+ [System.Net.ServicePointManager]::CertificatePolicy = New-Object Trus ...\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n + CategoryInfo : InvalidOperation: (System.Net.ServicePointManager:TypeName) [], RuntimeException\n + FullyQualifiedErrorId : TypeNotFound\n\nPS /Users/ffeldhaus> Invoke-WebRequest https://expired.badssl.com/ \nInvoke-WebRequest : An error occurred while sending the request.\nAt line:1 char:1\n+ Invoke-WebRequest https://expired.badssl.com/\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n + CategoryInfo : InvalidOperation: (Method: GET, Re...rShell/6.0.0\n}:HttpRequestMessage) [Invoke-WebRequest], HttpRequestException\n + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand\n```\n## Environment data\n\n\u003c!-- provide the output of $PSVersionTable -->\n\n``` powershell\nName Value\n---- ----- \nPSVersion 6.0.0-alpha\nPSEdition Core\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\nBuildVersion 3.0.0.0\nGitCommitId v6.0.0-alpha.9\nCLRVersion\nWSManStackVersion 3.0 \nPSRemotingProtocolVersion 2.3\nSerializationVersion 1.1.0.1\n```\n","author":{"url":"https://github.com/ffeldhaus","@type":"Person","name":"ffeldhaus"},"datePublished":"2016-08-19T08:40:51Z","url":"https://github.com/PowerShell/PowerShell/issues/1945"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:eb953410-f539-7a36-4779-ee6708c625ad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C10E:962B9:3EFD:4F04:6AFDB3C1 |
| html-safe-nonce | 46ec319f2a7b657b0cf8a2db5499b0a0a4274f0a10311e04f491550c053c398d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTBFOjk2MkI5OjNFRkQ6NEYwNDo2QUZEQjNDMSIsInZpc2l0b3JfaWQiOiI5MjIxODUwNDg2MzU1NjM3MTg1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6c1c83531e711e6ed1f5fe50c1d0bd9d86d78c8390146543dc213d70f4df000d |
| hovercard-subject-tag | issue:172082290 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/1945/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e772c42b4b8521d0f1f3507e06b6e5647c8a6bd90911ebb43cfbee92229b81cd/PowerShell/PowerShell/issues/1945 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e772c42b4b8521d0f1f3507e06b6e5647c8a6bd90911ebb43cfbee92229b81cd/PowerShell/PowerShell/issues/1945 |
| og:image:alt | On Windows, I was able to connect to HTTPS endpoints with invalid certificates by setting a certificate policy via System.Net.ServicePointManager to ignore invalid certificates. An integrated way t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ffeldhaus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3c532f4d069d6fbe9b1837450343d1b9e0619a7d5c4ba0b3b64fd8e0bae67c7e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5396ad00d1c6d19097aee7fc4d00a2eb03432c8f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width