首页 \ 问答 \ Powershell v3 Invoke-WebRequest HTTPS错误(Powershell v3 Invoke-WebRequest HTTPS error)

Powershell v3 Invoke-WebRequest HTTPS错误(Powershell v3 Invoke-WebRequest HTTPS error)

使用Powershell v3的Invoke-WebRequest和Invoke-RestMethod我已成功使用POST方法将json文件发布到https网站。

我使用的命令是

 $cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("cert.crt")
 Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Body $json -ContentType application/json -Method POST

但是当我尝试使用GET方法,如:

 Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Method GET

返回以下错误

 Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
 At line:8 char:11
 + $output = Invoke-RestMethod -Uri https://IPADDRESS/resource -Credential $cred
 +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest)      [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

我尝试使用以下代码来忽略SSL证书,但我不知道它是否真的做任何事情。

 [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

有人可以提供一些关于这里可能出现的问题的指导,以及如何解决这个问题?

谢谢


Using Powershell v3's Invoke-WebRequest and Invoke-RestMethod I have succesfully used the POST method to post a json file to a https website.

The command I'm using is

 $cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("cert.crt")
 Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Body $json -ContentType application/json -Method POST

However when I attempt to use the GET method like:

 Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Method GET

The following error is returned

 Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
 At line:8 char:11
 + $output = Invoke-RestMethod -Uri https://IPADDRESS/resource -Credential $cred
 +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest)      [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I have attempted using the following code to ignore SSL cert, but I'm not sure if its actually doing anything.

 [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

Can someone provide some guideance on what might be going wrong here and how to fix it?

Thanks


原文:https://stackoverflow.com/questions/11696944
更新时间:2023-06-18 12:06

最满意答案

结果对于所有这些都是一样的,你会得到一个新的空的不可变数组。 尽管不同的方法有不同的内存管理含义。 使用ARC这最终没有什么区别,但在ARC之前,您必须使用正确的版本或发送适当的保留,发布或自动释放消息。

[NSArray new][[NSArray alloc] init]返回一个+1保留计数的数组。 在ARC之前,您将不得不释放或自动释放该阵列,否则会泄漏内存。

[NSArray array]@[]返回已经自动释放的数组(保留计数0)。 如果你希望它在没有ARC的情况下继续存在,你必须手动保留它,否则当当前autorelease池被弹出时它会被释放。


The result is the same for all of them, you get a new empty immutable array. The different methods have different memory management implications though. Using ARC this makes no difference in the end, but before ARC you would have to use the right version or send appropriate retain, release or autorelease messages.

[NSArray new] and [[NSArray alloc] init] return an array with an +1 retain count. Before ARC you would have to release or autorelease that array or you'd leak memory.

[NSArray array] and @[] return an already autoreleased array (retain count 0). If you want it to stick around without ARC you'd have to manually retain it or it would be deallocated when the current autorelease pool gets popped.

相关问答

更多
  • NSMutableArray *persons = [NSMutableArray array]; for (int i = 0; i < myPersonsCount; i++) { [persons addObject:[[Person alloc] init]]; } NSArray *arrayOfPersons = [NSArray arrayWithArray:persons]; // if you want immutable array 你也可以在不使用NSMutableArray的 ...
  • 结果对于所有这些都是一样的,你会得到一个新的空的不可变数组。 尽管不同的方法有不同的内存管理含义。 使用ARC这最终没有什么区别,但在ARC之前,您必须使用正确的版本或发送适当的保留,发布或自动释放消息。 [NSArray new]和[[NSArray alloc] init]返回一个+1保留计数的数组。 在ARC之前,您将不得不释放或自动释放该阵列,否则会泄漏内存。 [NSArray array]和@[]返回已经自动释放的数组(保留计数0)。 如果你希望它在没有ARC的情况下继续存在,你必须手动保留它,否 ...
  • 你永远不会“重新启动”对象。 初始化意味着在新分配的实例上使用,并且可能会在初始化完成后做出假设。 在NSMutableDictionary的情况下,你可以使用setDictionary:用一个新字典或addEntriesFromDictionary:完全替换字典的内容addEntriesFromDictionary:从另一个字典中添加条目(除非存在冲突,否则不会删除当前条目)。 更一般地说,您可以释放该字典并在数组中创建字典的mutableCopy 。 You do not "reinit" object ...
  • 因为在一开始我用数组声明了所有的数组,如果在某个函数结束时,我返回了使用alloc创建的数组,我必须自动释放该数组,因为内存泄漏问题。 现在使用第一个声明我不需要释放任何东西 当你“销售”一个对象时,这是正确的。 但在其他情况下,当您在iOS上创建一个对象时,您可以在获取现成的自动释放的对象和调用alloc之后进行选择,然后释放,Apple希望您使用alloc和release,因为这会保留对象的生命周期短暂的,在你的控制之下。 这里的问题是,自动释放的对象生活在自动释放池中,并且可以堆积,直到池被排出,每当 ...
  • 这里有一些原因: http : //macresearch.org/difference-between-alloc-init-and-new 一些选择的是: new不支持自定义初始化器(如initWithString) alloc-init比new更为明确 一般意见似乎是你应该使用任何你喜欢的东西。 There are a bunch of reasons here: http://macresearch.org/difference-between-alloc-init-and-new Some sel ...
  • 不,不是NSArray 。 NSArray是一个使用结构的链表,因此它不会在幕后使用。 检查nil,至少使用NSArray是没有意义的。 但是,如果你使用像CCArray这样的集合类,例如来自cocos2d,那么用大数组检查nil可能是有益的。 尽管如此,iOS上的指针大小是8个字节,甚至1000个元素的C-Array也只有8 KB的RAM。 在大多数情况下,您将无法使用足够的内存来达到用完的程度。 另请注意,如果您的应用程序内存不足,则可以注册许多委托方法以对此进行警告并进行修复。 No, not wit ...
  • 当我的应用程序在我的任何设备或模拟器上的空白“已保存的照片”专辑中崩溃时,我注意到了这一点。 如果保存的照片中有照片,则不会发生错误。 如果您在模拟器上使用“重置数据和设置”,则很容易复制,并将您的相册留空。 我花了很多年时间试图寻找一种解决方法,但我无法做到。 我认为提交iOS错误报告是一个真正的好主意。 I noticed this when my app crashed on an empty 'Saved Photos' album on any of my devices, or the simu ...
  • 后面两种方法都是正确的,但我相信你想把它们放在一起! static NSDateFormatter *sharedInstance = nil; + (NSDateFormatter *)sharedInstance { if (sharedInstance == nil) { sharedInstance = [[NSDateFormatter alloc] init]; } return sharedInstance; } 注意:这样的类被称为单例。 阅读更多 ...
  • instancetype是一个关键字,表示“此方法的返回类型是此方法在其上调用的类的类型”(或子类)。 所以,如果你调用[Baseclass createWithString:] ,返回类型是Baseclass * 。 但是,假设您创建了一个不重写此方法的子类。 如果调用[Subclass createWithString:] ,则返回类型是Subclass * (不是Baseclass * )。 当一个类收到一条消息时, self指向Class对象。 所以当调用[Baseclass createWithS ...
  • [[NSArray alloc] init]返回一个空的不可变数组。 这没什么好奇怪的。 你还会从一种方法中返回什么意思“没有物品?” 编译器如何知道RAM中的对象计数或大小 对象计数为0.它是空的。 它在RAM中的大小是空NSArray的大小。 NSArray是一个对象,因此它有一些标准的objc_object开销,以及NSArray一些实例变量。 也就是说,作为一个实现细节,Cocoa优化了这一点,并且总是为所有空的NSArray对象返回相同的单例。 您可以通过以下方式演示: NSArray *a = ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)