如何设置 HttpURLConnection 的内容类型?
您知道如何在 HttpURLConnection< 上设置 Content-Type
/a>?
以下代码是在黑莓上使用的,我想要 Android 上的等效代码:
connection.setRequestProperty("content-type", "text/plain; charset=utf-8");
connection.setRequestProperty("Host", "192.168.1.36");
connection.setRequestProperty("Expect", "100-continue");
它适合 Android 吗?
请指教。
Do you know how to set Content-Type
on HttpURLConnection?
Following code is on Blackberry and I want the Android equivalent:
connection.setRequestProperty("content-type", "text/plain; charset=utf-8");
connection.setRequestProperty("Host", "192.168.1.36");
connection.setRequestProperty("Expect", "100-continue");
Is it right for android?
Please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您确实想使用 HttpURLConnection 您可以使用 setRequestProperty方法如下:
但是,如果我是你,我会考虑使用 Apache HTTP 库。它们的级别更高一些并且更易于使用。与他们一起,你可以这样做:
If you really want to use the HttpURLConnection you can use the setRequestProperty method like:
However, if I were you I'd look into using the Apache HTTP libraries. They're a little higher-level and easier to use. With them you would do it with something like: