# Upload files to website with curl using POST method

**URL:** <https://forums.powershell.org/t/upload-files-to-website-with-curl-using-post-method/20796>\
**Category:** PowerShell Help\
**Created:** [November 1, 2022, 10:09am UTC](https://forums.powershell.org/t/upload-files-to-website-with-curl-using-post-method/20796 "2022-11-01T10:09:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivcho\_pifcho](https://avatars.discourse-cdn.com/v4/letter/i/7ea924/32.png) [@ivcho\_pifcho](https://forums.powershell.org/u/ivcho_pifcho)\
**Post date:** [November 1, 2022, 10:09am UTC](https://forums.powershell.org/t/upload-files-to-website-with-curl-using-post-method/20796/1 "2022-11-01T10:09:44Z")

</div>

Hello,

I want to upload multi files to web site with power shell. Using this script - [[Upload file with powershell · GitHub](https://gist.github.com/lekpamartin/d5b104d953f6e0b4fd1cc00f3295d00c)].I tried to upload one file but not works for me. I modify the code using method POST:

```auto
$publishUrl="https://example.com/xxxxxx?cmd=upload"
$packageName = "C:\Users\xxxxx\Desktop\xxxxx\dummy.properties"
$username="xxxxx"
$password="xxxxxxx"

$params = @{
  UseBasicParsing = $true
  Uri = $publishUrl
  Method = "POST"
  InFile = $packageName
  Headers = @{
    ContentType = "application/json"
    Authorization = "Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$username`:$password")))" 
  }
  Verbose = $true
}
Invoke-WebRequest @params

```

When start the script I get the following response:

```auto
DETAILED: POST https://example.com/xxxxxx?cmd=upload with -1-byte
payload
DETAILED: received 0-byte response of content type

StatusCode : 200
StatusDescription :
Content : {}
RawContent : HTTP/1.1 200
                    Strict-Transport-Security: max-age=31536000;includeSubDomains
                    X-Frame-Options: SAMEORIGIN
                    X-Content-Type-Options: nosniff
                    X-XSS-Protection: 1; mode=block
                    vary: Origin
                    Access-Contro...
Headers : {[Strict-Transport-Security, max-age=31536000;includeSubDomains], [X-Frame-Options, SAMEORIGIN],
                    [X-Content-Type-Options, nosniff], [X-XSS-Protection, 1; mode=block]...}
RawContentLength : 0

```

What is wrong. I tried others command, but not work to me.

Thank you.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 1, 2022, 2:21pm UTC](https://forums.powershell.org/t/upload-files-to-website-with-curl-using-post-method/20796/2 "2022-11-01T14:21:44Z")

</div>

Hi, welcome back to the forum. What makes you think anything is wrong? Http status code 200 is a success code.

---

<div class="post-metadata">

**Author:** ![ivcho\_pifcho](https://avatars.discourse-cdn.com/v4/letter/i/7ea924/32.png) [@ivcho\_pifcho](https://forums.powershell.org/u/ivcho_pifcho)\
**Post date:** [November 1, 2022, 2:49pm UTC](https://forums.powershell.org/t/upload-files-to-website-with-curl-using-post-method/20796/3 "2022-11-01T14:49:12Z")

</div>

You are right, but i want to upload a file (dummy.properties) to this url -  
[https://example.com/xxxxxx?cmd=upload](https://example.com/xxxxxx?cmd=upload).  
When i play the script, i can’t upload the file with this script on this url.  
When I start the script in linux environment, it’s work and I can upload file to the url. I use this command:

```auto
curl --user $username:$password --request POST "$url" --form "file=@$path" --form "desc=$ver"

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/upload-files-to-website-with-curl-using-post-method/20796/4 "2024-05-16T20:16:27Z")

</div>

Closed on May 16, 2024, 8:16pm UTC


