URLConnection: setRequestProperty(String key, String value) : URLConnection « java.net « Java by API






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);
  }
}

   
    
  








Related examples in the same category

1.URLConnection: connect() throws IOException
2.URLConnection: getContentEncoding()
3.URLConnection: getContentType()
4.URLConnection: getExpiration()
5.URLConnection: getHeaderFields()
6.URLConnection: getHeaderField(int n)
7.URLConnection: getHeaderFieldKey(int n)
8.URLConnection: getInputStream()
9.URLConnection: getIfModifiedSince()
10.URLConnection: getLastModified()
11.URLConnection: getURL()
12.URLConnection: setAllowUserInteraction(boolean allowuserinteraction)
13.URLConnection: setDoInput(boolean doinput)
14.URLConnection: setDoOutput(boolean dooutput)
15.URLConnection: setIfModifiedSince(long ifmodifiedsince)
16.URLConnection: setUseCaches(boolean usecaches)