• In essence what I’m saying is the problem isn’t so much with your powershell code as with your actual request to BitBucket.  It thinks you’re a web browser, there’s probably some parameter they’ll accept (either in the headers, as a URI parameter after the ? or using a particular URI path) to tell them you just want to download the file, not view it.

     

    You could also try changing from this to that

    https://api.bitbucket.org/1.0/repositories/company/project/raw/HEAD/some/special/file.txt
    ftp://api.bitbucket.org/1.0/repositories/company/project/raw/HEAD/some/special/file.txt

     

  • There are a few things that could be going on, you’ll need to do a bit more digging to figure it out. I’ll start by suggesting a tool (Postman) and giving a bit of context into what’s probably going on.

    This is what an http conversation actually looks like. Red is what we send, blue is what we get back.
    wireshark google
    https://ibb.co/bEfn9o

    Here’s a practical example in postman (calling out to google.com)
    postman google
    https://ibb.co/isjavT

    Notice there’s 2 places we can send parameters, in the URI and in the Headers. One of the standard headers is Content-Type which indicates the format the web server is trying to send back to you.

    Try installing Postman, putting in your URI and playing around values you send in the URI and Headers, there’s probably a way to ask for it to send a text/plain instead of text/html file. Once you know what the URI and Headers need to be you should be able to translate your request into powershell code using the -URI and -Headers parameters

  • Chris posted an update 4 years, 1 month ago

    @mgarg007
    Trying to reply about using powershell’s invoke-webrequest and getting an unexpected file type, but having some delays getting added to the group and wanted to give you a timely response.

    There are a few things that could be going on, you’ll need to do a bit more digging to figure it out. I’ll start by suggesting a tool (Postman) and giving a bit of context into what’s probably going on.

    This is what an http conversation actually looks like. Red is what we send, blue is what we get back.
    https://ibb.co/bEfn9o

    Here’s a practical example in postman (calling out to google.com)
    https://ibb.co/isjavT

    Notice there’s 2 places we can send parameters, in the URI and in the Headers. One of the standard headers is Content-Type which indicates the format the web server is trying to send back to you.

    Try installing Postman, putting in your URI and playing around values you send in the URI and Headers, there’s probably a way to ask for it to send a text/plain instead of text/html file. Once you know what the URI and Headers need to be you should be able to translate your request into powershell code using the -URI and -Headers parameters

  • Chris became a registered member 4 years, 1 month ago

© 4sysops 2006 - 2022

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account