Tag archive for: java.io.OutputStream

How to send an HTTP request to a HTTP Basic Authentication endpoint in Java without using any external libraries

One common task for Java developers is to write codes that communicate with API endpoints. Chances are these endpoints could use HTTP Basic Authentication for authenticating the HTTP request sender.

Although there are good libraries to help us craft and send HTTP requests to a web server in Java, I prefer to use the Java core library so as to keep my Java program lightweight.

Referencing my earlier post on how to construct a HTTP request to an endpoint with HTTP basic authentication, this post documents how to send an HTTP request to a HTTP Basic Authentication endpoint in Java without using any external libraries.

How to upload a file via a HTTP multipart request in Java without using any external libraries

There was this situation when there was a need for my applet to send some log files (generated by some desktop application) on the remote clients.

To keep my applet lean, I chose to implement this file upload function by sending a HTTP multipart request when my applet loads on the remote client’s browser. Policies were in place to ensure that my applet was able to read the log files and send them back to a web server which will collect the log files.

This post documents how I can upload a file by sending a HTTP multipart request in Java without using any external libraries. For the sake of brevity, I used the server endpoint that I had discussed earlier to accept the file from the codes that will be mentioned in this post.