public static <T> T doPost(DbxRequestConfig requestConfig, String accessToken, String sdkUserAgentIdentifier, String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/List<HttpRequestor.Header> headers, ResponseHandler<T> handler) throws DbxException { headers = copyHeaders(headers); headers = addAuthHeader(headers, accessToken); return doPostNoAuth(requestConfig, sdkUserAgentIdentifier, host, path, params, headers, handler); }
/** * Convenience function for making HTTP POST requests. */ public static HttpRequestor.Response startPostNoAuth(DbxRequestConfig requestConfig, String sdkUserAgentIdentifier, String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/List<HttpRequestor.Header> headers) throws NetworkIOException { byte[] encodedParams = StringUtil.stringToUtf8(encodeUrlParams(requestConfig.getUserLocale(), params)); headers = copyHeaders(headers); headers.add(new HttpRequestor.Header("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")); return startPostRaw(requestConfig, sdkUserAgentIdentifier, host, path, encodedParams, headers); }
/** * Convenience function for making HTTP POST requests. Like startPostNoAuth but takes byte[] instead of params. */ public static HttpRequestor.Response startPostRaw(DbxRequestConfig requestConfig, String sdkUserAgentIdentifier, String host, String path, byte[] body, /*@Nullable*/List<HttpRequestor.Header> headers) throws NetworkIOException { String uri = buildUri(host, path); headers = copyHeaders(headers); headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier); headers.add(new HttpRequestor.Header("Content-Length", Integer.toString(body.length))); try { HttpRequestor.Uploader uploader = requestConfig.getHttpRequestor().startPost(uri, headers); try { uploader.upload(body); return uploader.finish(); } finally { uploader.close(); } } catch (IOException ex) { throw new NetworkIOException(ex); } }
/** * Convenience function for making HTTP PUT requests. */ public static HttpRequestor.Uploader startPut(DbxRequestConfig requestConfig, String accessToken, String sdkUserAgentIdentifier, String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/List<HttpRequestor.Header> headers) throws NetworkIOException { headers = copyHeaders(headers); headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier); headers = addAuthHeader(headers, accessToken); String url = buildUrlWithParams(requestConfig.getUserLocale(), host, path, params); try { return requestConfig.getHttpRequestor().startPut(url, headers); } catch (IOException ex) { throw new NetworkIOException(ex); } }
/** * Convenience function for making HTTP GET requests. */ public static HttpRequestor.Response startGet(DbxRequestConfig requestConfig, String accessToken, String sdkUserAgentIdentifier, String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/List<HttpRequestor.Header> headers) throws NetworkIOException { headers = copyHeaders(headers); headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier); headers = addAuthHeader(headers, accessToken); String url = buildUrlWithParams(requestConfig.getUserLocale(), host, path, params); try { return requestConfig.getHttpRequestor().doGet(url, headers); } catch (IOException ex) { throw new NetworkIOException(ex); } }