【发布时间】:2016-02-08 19:23:09
【问题描述】:
我需要 HttpUrlConnection 来使用 POST 方法,但它的播放效果不好。
connection = (HttpURLConnection) link.openConnection();
connection.setRequestMethod("POST");
...
在调试器中:
- 在第一行我看到
connection = null符合预期 - 第二行我可以看到
connection.method = "GET"符合预期 - 进一步,我看到
connection.method = "GET"这不是预期的
如何让 HttpUrlConnection 使用 POST ?
解决方案
如果您在“HTTPS”协议上打开HttpUrlconnection,该连接将永久覆盖到“GET”的连接。
如果手动设置,通过“HTTP”连接将允许“POST”方法。
【问题讨论】:
-
如果你使用HTTPS,你应该使用HttpsURLConnection:developer.android.com/reference/javax/net/ssl/…
-
在整个应用程序中建立了多个连接,一些 http 一些 https,因此为什么要追查这个 bug 有点乱。
-
啊,我明白了。很高兴你把它整理好了!
标签: android http-post httpurlconnection