Java HttpURLConnection中的setDoInput和setDoOutput的目的是什么? [英] What is the purpose of setDoInput and setDoOutput in Java HttpURLConnection?

查看:95
本文介绍了Java HttpURLConnection中的setDoInput和setDoOutput的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpURLConnection.setDoInput HttpURLConnection.setDoOutput 的功能或目的是什么?

What is the function or purpose of HttpURLConnection.setDoInput and HttpURLConnection.setDoOutput?

推荐答案

来自

如果要使用URL连接进行输入,请将DoInput标志设置为true,否则将其设置为false.默认值为true.

Set the DoInput flag to true if you intend to use the URL connection for input, false if not. The default is true.

如果要使用URL连接进行输出,请将DoOutput标志设置为true,否则将其设置为false.默认值为false.

Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. The default is false.

就实际用途而言,Oracle代码中似乎没有任何内容对 doInput 变量进行检查.但是, doOutput 的默认值为false会阻止您调用HTTP POST请求所需的 getOutputStream().因此,这是一种提前指示您希望写入 OutputStream 而不实际建立它的方法.

As for the actual purpose, it doesn't appear that anything in the Oracle code checks on the doInput variable. However the doOutput default of false will prevent you from calling getOutputStream() necessary for HTTP POST requests. So it is a way to indicate ahead of time that you expect to write to an OutputStream without actually establishing it.

这篇关于Java HttpURLConnection中的setDoInput和setDoOutput的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆