Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: What is the purpose of setDoInput in URLConnection [duplicate]

Possible Duplicate:
Java HttpURLConnection

Would this method be used for example if I want to read the response to a POST method call from the server I am connected to?

like image 776
Teererai Marange Avatar asked Jul 04 '12 11:07

Teererai Marange


People also ask

What is setDoInput?

setDoInput(true) is used to fetch the response and is true by default. When using a different method e.g. GET, you have nothing to pass to the connection, so an OutputStream is not necessary.

What is the difference between URLConnection and HttpURLConnection?

URLConnection is the base class. HttpURLConnection is a derived class which you can use when you need the extra API and you are dealing with HTTP or HTTPS only. HttpsURLConnection is a 'more derived' class which you can use when you need the 'more extra' API and you are dealing with HTTPS only.

What does getContentType return?

getContentType. Returns the value of the content-type header field. Returns: the content type of the resource that the URL references, or null if not known.

What is URLConnection in Java?

The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL.


1 Answers

I've never encountered a case for setting it false. You always want to read something, at least the response code.

like image 106
user207421 Avatar answered Oct 20 '22 03:10

user207421