575
votes
3answers
241k views
How to use java.net.URLConnection to fire and handle HTTP requests?
URLConnection is pretty often asked here and the Oracle tutorial is too concise about it. So
how do I use it to fire and handle HTTP requests?
Are there other hints and best practices on this that ...
162
votes
18answers
150k views
HTTP URL Address Encoding in Java
My Java standalone application gets a URL (which points to a file) from the user and I need to hit it and download it. The problem I am facing is that I am not able to encode the HTTP URL address ...
150
votes
9answers
269k views
How to send HTTP request in java?
I want to compose a HTTP request message in java and then want to send it to a HTTP WebServer.
I also want the document content of the page recieved which I would have recieved if I had sent the same ...
75
votes
2answers
60k views
How do I make an http request using cookies on Android?
I'd like to make an http request to a remote server while properly handling cookies (eg. storing cookies sent by the server, and sending those cookies when I make subsequent requests). It'd be nice ...
53
votes
4answers
48k views
Java URL encoding
I've searched a few times now, but not come up with suitable answer to my problem...
Say I have a URL
http://example.com/query?q=
and I have a query entered by the user such as:
"random word ...
50
votes
5answers
55k views
How do you Programmatically Download a Webpage in Java
I would like to be able to fetch a web page's html and save it to a String, so I can do some processing on it. Also, how could I handle various types of compression.
How would I go about doing that ...
46
votes
7answers
32k views
HttpServletRequest to complete URL
I have an HttpServletRequest object.
How do I get the complete and exact URL that caused this call to arrive at my servlet?
Or at least as accurately as possible, as there are perhaps things that ...
42
votes
3answers
108k views
Java - sending HTTP parameters via POST method easily
I am successfully using this code to send HTTP requests with some parameters via GET method
function void sendRequest(String request)
{
// i.e.: request = ...
35
votes
9answers
23k views
Best way to upload multiple files from a browser
I'm working on a web application. There is one place where the user can upload files with the HTTP protocol. There is a choice between the classic HTML file upload control and a Java applet to upload ...
33
votes
2answers
56k views
Android write to sd card folder
I am using the following code to download a file from my server then write it to the root directory of the sd card, it all works fine:
package com.downloader;
import java.io.File;
import ...
32
votes
8answers
11k views
Does Java have a complete enum for HTTP response codes?
I'm wondering if there is an enum type in some standard Java class library that defines symbolic constants for all of the valid HTTP response codes. It should support conversion to/from the ...
31
votes
4answers
49k views
29
votes
5answers
41k views
How can I make a multipart/form-data POST request using Java?
In the days of version 3.x of Apache Commons HttpClient, making a multipart/form-data POST request was possible (an example from 2004). Unfortunately this is no longer possible in version 4.0 of ...
27
votes
6answers
52k views
Http Basic Authentication in Java using HttpClient?
I am trying to mimic the functionality of this curl command in Java:
curl --basic --user username:password -d "" http://ipaddress/test/login
I wrote the following using Commons HttpClient 3.0 but ...
26
votes
5answers
13k views
What is the best Java library to use for HTTP POST, GET etc.?
What is the best Java library to use for HTTP POST, GET etc. in terms of performance, stability, maturity etc.? Is there one particular library that is used more than others?
My requirements are ...