HttpURLConnection PUT to Google Cloud Storage giving error 403
I just figured out that HttpURLConnection
adds Content-Type
header with value application/x-www-form-urlencoded
by itself. I've done it using HTTP sniffer on my android emulator.
This auto-added header caused signature mismatch. After I changed the code on the server-side to allow requests with Content-Type: application/x-www-form-urlencoded
it generates the right signature and it works fine.
Thank you @morpheus05 for your commitment.
Please set your Content-Type
like this.
connection.setRequestProperty("Content-Type"," ");
Because HttpsUrlConnection
automatically generate Content-Type as
"Content-Type: application/x-www-form-urlencoded"
this will cause a signature mismatch.