0
votes

So I'm working on a blockchain project and the code itself has been fixed to where it doesn't give me errors. It tells me "Running on xyz"

That said, when I go to PowerShell and run the Invoke-WebRequest as others have mentioned previously (instead of curl) I get the error:

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

Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json" value of type "System.String" to type

"System.Collections.IDictionary". At line:1 char:47 + ... "localhost:5000/txion" \ -H "Content-Type: application/json" \ -d '{ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

2

2 Answers

2
votes

You could try the following instead:

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

Or:

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

Invoke-RestMethod makes this simple. The response is automatically loaded into a System.Management.Automation.PSCustomObject for you.

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