运行简单的未经授权的 Rest 查询时发生意外错误 [英] Unexpected error occurred running a simple unauthorized Rest query

查看:136
本文介绍了运行简单的未经授权的 Rest 查询时发生意外错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不执行身份验证检查的休息端点.我可以从 Linux 运行一个简单的 curl 命令:

curl -k https://application/api/about

这是响应.

但是,如果在 PowerShell 上尝试以下操作,则会失败:

Invoke-RestMethod https://application/api/about

然后我得到:

Invoke-RestMethod :基础连接已关闭:发送时发生意外错误.在行:1 字符:1+ Invoke-RestMethod $Application+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException+ FullQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

有人可以告诉我如何解决这个问题吗?

尝试使用 Invoke-WebRequest:

Invoke-WebRequest -Uri "https://application/api/about"

<块引用>

Invoke-WebRequest:底层连接已关闭:An发送时发生意外错误.在行:1 字符:1+ Invoke-WebRequest -Uri "https://application/api/a ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest],网络异常+ FullQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

解决方案

使用:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

取自Powershell 3.0 Invoke-WebRequest HTTPS 失败所有请求.

I have a rest endpoint that doesn't perform an authentication check. I can run a simple curl commmand from Linux:

curl -k https://application/api/about

This responds.

However if try the following on PowerShell it fails:

Invoke-RestMethod https://application/api/about

Then I get:

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-RestMethod $Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Could some one please tell me how I can get around this problem ?

EDIT:

Trying with Invoke-WebRequest:

Invoke-WebRequest -Uri "https://application/api/about"

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At line:1 char:1 + Invoke-WebRequest -Uri "https://application/api/a ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

解决方案

Using:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Taken from Powershell 3.0 Invoke-WebRequest HTTPS Fails on All Requests.

这篇关于运行简单的未经授权的 Rest 查询时发生意外错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆