这到底是什么URLConnection.setDoOutput()的影响?到底是什么、URLConnection、setDoOutput

由网友(安于现状丶)分享简介:还有 setDoOutput()在的URLConnection 。据documentation我应该设置doOutput标志为true,如果你打算使用输出的URL连接,虚假的。Set the DoOutput flag to true if you intend to use the URL connection f...

还有 setDoOutput()的URLConnection 。据documentation我应该

设置doOutput标志为true,如果你打算使用输出的URL连接,虚假的。

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

现在我面临正是这个问题 - Java运行时将请求转换发表曾经 setDoOutput(真)被调用,服务器只响应 GET 请求。我想知道,如果我删除 setDoOutput(真)从code。

Now I'm facing exactly this problem - the Java runtime converts the request to POST once setDoOutput(true) is called and the server only responds to GET requests. I want to understand what happens if I remove that setDoOutput(true) from the code.

究竟这会不会影响?假设我将它设置为 - 我现在能做到什么我不能做呢?请问我能不能执行 GET 请求?什么是输出,在此方法的上下文

What exactly will this affect? Suppose I set it to false - what can I do now and what can't I do now? Will I be able to perform GET requests? What is "output" in context of this method?

推荐答案

您需要的,如果你想发送给它设置为true(输出的)请求主体,例如用POST或PUT请求。通过GET,你通常不会派一个机构,所以你不需要它。

You need to set it to true if you want to send (output) a request body, for example with POST or PUT requests. With GET, you do not usually send a body, so you do not need it.

发送请求体本身通过连接的输出流进行:

Sending the request body itself is done via the connection's output stream:

conn.getOutputStream().write(someBytes);
阅读全文

相关推荐

最新文章