URLConnection: setRequestProperty(String key, String value)
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
class MainClass {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.x.com");
URLConnection urlc = url.openConnection();
urlc.setRequestProperty("User-Agent", "Mozilla 5.0 (Windows; U; "
+ "Windows NT 5.1; en-US; rv:1.8.0.11) ");
InputStream is = urlc.getInputStream();
int c;
while ((c = is.read()) != -1)
System.out.print((char) c);
}
}
Home
Java Book
Networking
Java Book
Networking
URLConnection:
- URLConnection
- URLConnection: connect() throws IOException
- URLConnection: getContentEncoding()
- URLConnection: getExpiration()
- URLConnection: getHeaderFields()
- URLConnection: getHeaderField(int n)
- URLConnection: getHeaderFieldKey(int n)
- URLConnection: getIfModifiedSince()
- URLConnection: getLastModified()
- URLConnection: getURL()
- URLConnection: setAllowUserInteraction(boolean allowuserinteraction)
- URLConnection: setDoOutput(boolean dooutput)
- URLConnection: setIfModifiedSince(long ifmodifiedsince)
- URLConnection: setRequestProperty(String key, String value)
- URLConnection: setUseCaches(boolean usecaches)