The example shows how to create a dataset asset from a password protected URL (Basic HTTP Auth).
Search This Blog
Java: HTTP GET data from URL (with basic HTTP Auth)
The example shows how to do HTTP GET to download a file from URL. It also include an example to call Mediaflux client api to create a dataset from the url by piping the streams.
encode Base64 string in command line
- Encode base64 string:
echo -n Secret | base64
- Decode base64 string:
echo -n U2VjcmV0 | base64 -D
Note:
When encoding, -n must be specified. otherwise, a newline character will always be appended, which will cause unexpected result.See http://askubuntu.com/questions/694216/base64-encode-is-giving-ambigious-results
make Java HttpURLConnection support MKCOL PROFIND and other non-standard HTTP methods
private static void setRequestMethod(HttpURLConnection conn, String method) throws Throwable { try { conn.setRequestMethod(method); } catch (ProtocolException e) { Class<?> c = conn.getClass(); Field methodField = null; Field delegateField = null; try { delegateField = c.getDeclaredField("delegate"); } catch (NoSuchFieldException nsfe) { } while (c != null && methodField == null) { try { methodField = c.getDeclaredField("method"); } catch (NoSuchFieldException nsfe) { } if (methodField == null) { c = c.getSuperclass(); } } if (methodField != null) { methodField.setAccessible(true); methodField.set(conn, method); } if (delegateField != null) { delegateField.setAccessible(true); HttpURLConnection delegate = (HttpURLConnection) delegateField.get(conn); setRequestMethod(delegate, method); } } }
Subscribe to:
Posts (Atom)