HttpURLConnection PUT to Google Cloud Storage giving error 403

谁都会走 提交于 2019-12-05 00:36:32
mysliwiec_tech

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.

Nison Cheruvathur

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!