URLConnection addRequestProperty - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for URLConnection addRequestProperty method.

This code example shows how to use the following methods:addRequestProperty, getOutputStream, setDoOutput
	 * @throws IOException if writing to stream fails 
	 *  
	 */ 
	@Override 
	protected void addContent(URLConnection con) throws IOException {
		con.setDoOutput(true);
		con.addRequestProperty("Content-Type", mime);
		con.addRequestProperty("Content-Length", String.valueOf(content.length));
		OutputStream os = con.getOutputStream();
		writeContent(os);
		os.close();
	} 
 
	@Override 
	public void writeContent(OutputStream os) throws IOException {
		os.write(content);
	} 
 
	/** Used as a mime part, writing content headers */ 
	@Override 
7
CodeRank
This code example shows how to use the following methods:addRequestProperty, connect, setConnectTimeout, setReadTimeout, setRequestProperty
        URLConnection connection = openConnection(url);
        if(connection instanceof HttpURLConnection){
            ((HttpURLConnection) connection).setRequestMethod("GET");
        } 
 
        connection.connect();
 
        return new SimpleHTTPResponse(connection);
    } 
 
    /** 
     * @see org.geotools.data.ows.HTTPClient#post(java.net.URL, java.io.InputStream, 
     *      java.lang.String) 
     */ 
    public HTTPResponse post(final URL url, final InputStream postContent,
            final String postContentType) throws IOException {
 
        URLConnection connection = openConnection(url);
        if (connection instanceof HttpURLConnection) {
            ((HttpURLConnection) connection).setRequestMethod("POST");

7
CodeRank
This code example shows how to use the following methods:addRequestProperty, getContentEncoding, getInputStream
	@Override 
	public void process(final String urlStr) {
		try { 
			final URL url = new URL(urlStr);
			final URLConnection con = url.openConnection();
			con.addRequestProperty("Accept", accept);
			con.addRequestProperty("Accept-Charset", encoding);
			String enc = con.getContentEncoding();
			if (enc == null) {
				enc = encoding;
			} 
			getReceiver().process(new InputStreamReader(con.getInputStream(), enc));
		} catch (IOException e) {
			throw new MetafactureException(e);
		} 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:setRequestMethod, addRequestProperty, getOutputStream, setDoOutput, setRequestProperty
    } 
 
    public static URLConnection httpPostCompressed(WebServer webServer, String path, String body) throws IOException {
        URL url = new URL(webServer.getUri().toURL(), path);
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.addRequestProperty("Content-Encoding", "gzip");
        urlConnection.setRequestMethod("POST");
        urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        urlConnection.setDoOutput(true);
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(baos);
        gzip.write(body.getBytes(Charset.forName("UTF8")));
        gzip.close();
 
        urlConnection.getOutputStream().write(baos.toByteArray());
        return urlConnection;
    } 
 
    public static String contents(URLConnection urlConnection) throws IOException {
        int length = urlConnection.getContentLength();
9
CodeRank
This code example shows how to use the following methods:addRequestProperty
            setUserAgent((HttpURLConnection) urlConnection);
        } 
    } 
     
    static public void setUserAgent(HttpURLConnection httpConnection) {
        httpConnection.addRequestProperty("User-Agent", getUserAgent());
    } 
 
    static public String getUserAgent() {
        return "OpenRefine/" + FULL_VERSION;
    } 
} 
6
CodeRank
This code example shows how to use the following methods:addRequestProperty
    String t = token.token;
    if (t != null) {
      if (!t.startsWith("\"")) {
        t = "\"" + t + "\"";
      } 
      conn.addRequestProperty("Cookie", AUTH_COOKIE_EQ + t);
    } 
  } 
 
  /** 
   * Helper method that extracts an authentication token received from a connection. 
   * <p/> 
   * This method is used by {@link Authenticator} implementations. 
   * 
   * @param conn connection to extract the authentication token from. 
   * @param token the authentication token. 
   * 
   * @throws IOException if an IO error occurred. 
   * @throws AuthenticationException if an authentication exception occurred. 
   */ 
6
CodeRank
This code example shows how to use the following methods:addRequestProperty, getContentEncoding, getInputStream
	@Override 
	public void process(final String urlStr) {
		try { 
			final URL url = new URL(urlStr);
			final URLConnection con = url.openConnection();
			con.addRequestProperty("Accept", accept);
			con.addRequestProperty("Accept-Charset", encoding);
			String enc = con.getContentEncoding();
			if (enc == null) {
				enc = encoding;
			} 
			getReceiver().process(new InputStreamReader(con.getInputStream(), enc));
		} catch (IOException e) {
			throw new MetafactureException(e);
		} 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:addRequestProperty, getInputStream, setConnectTimeout, setDoOutput
    } 
 
    private boolean read() { 
        try { 
            final URLConnection conn = this.url.openConnection();
            conn.setConnectTimeout(5000);
 
            if (this.apiKey != null) {
                conn.addRequestProperty("X-API-Key", this.apiKey);
            } 
            conn.addRequestProperty("User-Agent", "Updater (by Gravity)");
 
            conn.setDoOutput(true);
 
            final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            final String response = reader.readLine();
 
            final JSONArray array = (JSONArray) JSONValue.parse(response);
 
            if (array.size() == 0) {
6
CodeRank
This code example shows how to use the following methods:getResponseCode, setRequestMethod, addRequestProperty, connect, getInputStream
    @Test 
    public void testHeaderListMultipleHeaders() throws Exception { 
        final URL url = new URL(getBaseUri().toString());
        final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "text/plain");
        connection.setRequestProperty("hello", "world");
        connection.addRequestProperty("hello", "universe");
 
        connection.setDoOutput(false);
        connection.connect();
 
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(ReaderWriter.readFromAsString(new InputStreamReader(connection.getInputStream())),
                equalTo("2:[world, universe]")); 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:disconnect, addRequestProperty, connect, getInputStream, getOutputStream
			} 
			else 
			{ 
				httpConnect = (HttpURLConnection) url.openConnection();
			} 
			httpConnect.setConnectTimeout( connectTimeout );
			httpConnect.setReadTimeout( readTimeout );
			httpConnect.setDoOutput(true);
			httpConnect.addRequestProperty("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
			 
			httpConnect.connect();
			 
			OutputStream os = httpConnect.getOutputStream();
			p_entity.writeTo(os);
			os.flush();
 
			InputStream content 	= httpConnect.getInputStream();
			strResponse 	 	= BaseHelper.convertStreamToString(content);
			BaseHelper.log(TAG, "response " + strResponse);
		} 

6
CodeRank

Related URLConnection addRequestProperty Questions & Answers:

addRequestProperty Method Overview
Adds a general request property specified by a key-value pair.
See Code Examples for other Java 8 URLConnection Methods: