mikedopp icon

restexample

mikedopp | PRO | 03/16/18 08:41:24 PM UTC | 0 ⭐ | 310 👁️ | Never ⏰ | []
PowerShell |

830 B

|

None

|

0 👍

/

0 👎

$user = "admin"
$pass = "admin123"
$pair = "${user}:${pass}"
 
$fileName = "0.iso";
$sourceFilePath = "C:\\$fileName";
 
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
 
#$headers = @{ Authorization = $basicAuthValue; "Content-Length" = $sourceFilePath.Length } #Err You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.
$headers = @{ Authorization = $basicAuthValue }
$uri = "http://nexus.lab.local:8081/nexus/content/sites/myproj/0.iso" 
 
$output = Invoke-WebRequest -Uri $uri -Headers $headers -Method Post -InFile $sourceFilePath -ContentType "multipart/form-data" -TimeoutSec 36000 -Verbose -Debug
$Error[0].InvocationInfo.Line
$output
Write-Host "###################################"
$Error[0]

Comments