{"id":9583,"date":"2024-01-15T22:42:20","date_gmt":"2024-01-15T21:42:20","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=9583"},"modified":"2024-07-23T22:55:25","modified_gmt":"2024-07-23T20:55:25","slug":"windows-invoke-restmethod-the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-receive","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/windows-invoke-restmethod-the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-receive\/","title":{"rendered":"Windows: Invoke-RestMethod =>The underlying connection was closed: An unexpected error occurred on a receive."},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_9583 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_9583')){$('.twoclick_social_bookmarks_post_9583').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Windows%3A%20Invoke-RestMethod%20%3D%26gt%3BThe%20underlying%20connection%20was%20closed%3A%20An%20unexpected%20error%20occurred%20on%20a%20receive.\",\"the_excerpt\":\"Hi%2C%20%0D%0A%0D%0AInvoke-RestMethod%20or%20Invoke-WebRequest%20uses%20by%20default%20TLS%201.0.%20This%20protocal%20is%20outdated%20and%20would%20be%20not%20accepted%20by%20the%20most%20Webservers%20anymore.%20%0D%0A%0D%0AUsually%20this%20results%20in%20the%20following%20error%20message%3A%0D%0AThe%20underlying%20connection%20was%20closed%3A%20An%20unexpected%20error%20occurred%20on%20a%20receive.%0D%0A%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/windows-invoke-restmethod-the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-receive\\\/\",\"post_id\":9583,\"post_title_referrer_track\":\"Windows%3A+Invoke-RestMethod+%3D%26gt%3BThe+underlying+connection+was+closed%3A+An+unexpected+error+occurred+on+a+receive.\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi, <\/p>\n<p>Invoke-RestMethod or Invoke-WebRequest uses by default TLS 1.0. This protocal is outdated and would be not accepted by the most Webservers anymore. <\/p>\n<p>Usually this results in the following error message:<br \/>\n<strong>The underlying connection was closed: An unexpected error occurred on a receive.<\/strong><\/p>\n<p><!--more--><\/p>\n<p>Solution: Set the protocol version before calling those command-lets.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\&gt; &#x5B;Net.ServicePointManager]::SecurityProtocol = &#x5B;Net.SecurityProtocolType]::Tls12\r\nPS D:\\&gt; Invoke-RestMethod -Method &quot;GET&quot; -Uri &quot;https:\/\/myHOst.myDomain.org\/v1\/myAPICall&quot; -Headers $headers\r\n<\/pre>\n<p>Michael <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, Invoke-RestMethod or Invoke-WebRequest uses by default TLS 1.0. This protocal is outdated and would be not accepted by the most Webservers anymore. Usually this results in the following error message: The underlying connection was closed: An unexpected error occurred on a receive.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344,5],"tags":[89,1946,1939,133,82,433,20],"class_list":["post-9583","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","category-windowsknowhow","tag-error","tag-invoke-restmethod","tag-invoke-webrequest","tag-powershell","tag-ssl","tag-tls","tag-windows-2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=9583"}],"version-history":[{"count":1,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9583\/revisions"}],"predecessor-version":[{"id":9584,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9583\/revisions\/9584"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=9583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=9583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=9583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}