简体   繁体   中英

How to convert Curl command to Powershell in Visual Studio

I'm working in a project in Visual Studio (C#). I´ve been trying to convert this Curl command to PowerShell command, but can't achieve it.

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: 
application/json" --data '{"path": "<subgroup_path>", "name": "<subgroup_name>", "parent_id": 
<parent_group_id> }' "https://gitlab.example.com/api/v4/groups/"

I've seen plenty examples and I've tried many of them without success.

My PowerShell command:

Invoke-RestMethod -Method Post -Uri http://<my_domain>/api/v4/groups/ -Headers '{"PRIVATE-TOKEN": 
"<my_token>"}' -ContentType "application/json" -Body '{"path": "<my_new_group>", "name": 
"<my_new_group>", "parent_id": 5 }'

And I get this error:

Cannot bind parameter 'Headers'. Cannot convert the "PRIVATE-TOKEN: <my_token>" value of type 
"System.String" to type "System.Collections.IDictionary".

I also tried:

Invoke-WebRequest "http://<my_domain>/api/v4/groups" -Headers @{'accept' = 
'application/json'; 'PRIVATE-TOKEN' = '<my_token>'} -Method Post -Body 
@{"path": "<my_new_group>", "name": "<my_new_group>", "parent_id": 5 }

I've even changed this parameter in last command:

-Headers {'u'='<my_user_name>:<my_password>'}

I really need some advice or correction on how to launch this command. If anyone has any ideas or advice I would appreciate it.

Thanks in advance!

Fortunately, just changing what Ocaso Portal said I obtained the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM