簡體   English   中英

將Curl請求轉換為Powershell

[英]Converting Curl request to powershell

我正在嘗試在電源外殼中傳遞圖像來復制此cURL請求

curl -u user:apikey -F ‘data=@1234.jpg’
https://denton.gradesfirst.com/api/users/pictures

我通過身份驗證很好,但是不知道在'data=@1234.jpg'中復制'data=@1234.jpg' ,因此其他系統將知道圖片在哪里。

$username = "username"
$password = "apikey"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))



Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -uri "https://test.test.test.com/api/users/pictures" -Method Put -InFile "C:\Users\username\Downloads\pic-2017\210569.jpg" -ContentType 'image/jpg'

這是您必須使用invoke-rest方法的常見誤稱。

這應該為您工作。 如果需要非交互輸入憑據,只需將它們保存到文件中,然后將其拉入相同的$ cred變量-命令將保持不變。

$creds = Get-Credential
$url = "https://denton.gradesfirst.com/api/users/pictures"
Invoke-WebRequest -Credential $creds -Method Post -Uri $url -ContentType "application/x-www-form-urlencoded" -InFile "1234.jpg"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM