By default the
URLConnection
sends an HTTP GET request to the webserver. If you want to send an
HTTP POST request instead, call the URLConnection.setDoOutput(true)
method, like this: URL url = new URL("https://vigyancode.blogspot.com/");
URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
Once you have set called
setDoOutput(true)
you can open the URLConnection's
OutputStream
like
this: OutputStream output = urlConnection.getOutputStream();
Using this
OutputStream
you can write any data you want in the body of the HTTP request.
Remember to close the
OutputStream
when you are done writing data to it.
0 comments:
Post a Comment