卷曲+调用RestMethod

时间:2019-03-07 03:56:12

标签: windows powershell curl blockchain pycurl

所以我正在研究一个区块链项目,并且代码本身已经固定在不会给我错误的地方。它告诉我“在xyz上运行”

也就是说,当我像其他人之前提到的那样(而不是curl)进入PowerShell并运行Invoke-WebRequest时,出现错误:

PS C:\Users\sebt1> Invoke-WebRequest "localhost:5000/txion" \ -H "Content-Type: 
    application/json" \ -d '{"from": "akjflw", "to":"fjlakdj", "amount": 3}'
  

Invoke-WebRequest:无法绑定参数“ Headers”。无法转换   类型“ System.String”的“ Content-Type:application / json”值   键入

     

“ System.Collections.IDictionary”。在线:1字符:47   + ...“本地主机:5000 / txion” \ -H“内容类型:application / json” \ -d'{...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   + CategoryInfo:InvalidArgument:(:) [Invoke-WebRequest],ParameterBindingException + FullyQualifiedErrorId:   CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

2 个答案:

答案 0 :(得分:0)

您可以尝试以下方法:

Invoke-WebRequest "http://localhost:5000/txion" -Method POST -Headers @{"Content-Type" = "application/json"} -body @{"from" = "akjflw"; "to" = "fjlakdj"; "amount" = 3}

或者:

Invoke-WebRequest "http://localhost:5000/txion" -Method POST -Content-Type "application/json" -body @{"from" = "akjflw"; "to" = "fjlakdj"; "amount" = 3}

答案 1 :(得分:0)

Invoke-RestMethod使这一过程变得简单。响应会自动为您加载到System.Management.Automation.PSCustomObject中。

Invoke-RestMethod localhost:5000/txion -Method Post -Body @{"from": "akjflw"; "to":"fjlakdj"; "amount": 3; }