Refine search
urlConnection.setRequestMethod("PUT"); urlConnection.setUseCaches(false); urlConnection.setDoOutput(true); urlConnection.setFixedLengthStreamingMode(fileSizeInt); urlConnection.setRequestProperty("Content-Type", "application/octet-stream;"); for (Entry<String, String> header : slot.getHeaders().entrySet()) {
JsonObject jws = getJws(encodedProtectedHeader, encodedPayload, encodedSignature); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(POST); connection.setRequestProperty(CONTENT_TYPE, JOSE_JSON_CONTENT_TYPE); connection.setRequestProperty(ACCEPT_LANGUAGE, Locale.getDefault().toLanguageTag()); connection.setRequestProperty(USER_AGENT, USER_AGENT_STRING); connection.setDoOutput(true); connection.setFixedLengthStreamingMode(jws.toString().length()); connection.connect(); try (OutputStream out = connection.getOutputStream()) {
connection.setRequestMethod(DataSpec.getStringForHttpMethod(httpMethod)); if (httpBody != null) { connection.setFixedLengthStreamingMode(httpBody.length); connection.connect(); OutputStream os = connection.getOutputStream();
connection.setRequestMethod(request.getRequestMethod().getValue()); long contentLength = request.getContentLength(); if (contentLength <= Integer.MAX_VALUE) connection.setFixedLengthStreamingMode((int) contentLength); else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) connection.setFixedLengthStreamingMode(contentLength); else connection.setChunkedStreamingMode(256 * 1024);
setRequestMethodViaJreBugWorkaround(uc, httpMethod); } else { uc.setRequestMethod(httpMethod); uc.setFixedLengthStreamingMode(request.getLength()); } else { uc.setFixedLengthStreamingMode(length);
setRequestMethodViaJreBugWorkaround(uc, httpMethod); } else { uc.setRequestMethod(httpMethod); uc.setFixedLengthStreamingMode(request.getLength()); } else { uc.setFixedLengthStreamingMode(length);
setRequestMethodViaJreBugWorkaround(uc, httpMethod); } else { uc.setRequestMethod(httpMethod); uc.setFixedLengthStreamingMode(request.getLength()); } else { uc.setFixedLengthStreamingMode(length);
urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty("X-HTTP-Method-Override", "PUT"); urlConnection.setDoOutput(true); urlConnection.setFixedLengthStreamingMode(chunk); urlConnection.setRequestProperty("Content-Type", "video/3gpp"); urlConnection.setRequestProperty("Content-Range", String.format("bytes %d-%d/%d", start, end, connection.setRequestProperty("X-GData-Key", String.format("key=%s", DEVELOPER_KEY)); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/atom+xml");
urlConnection.setRequestMethod(reqType); urlConnection.setFixedLengthStreamingMode(cachedBytesLenght); urlConnection.getOutputStream().write(cachedBytes, 0, cachedBytesLenght); } else if (request.getByteData() != null) { urlConnection.setRequestProperty("Content-Length", String.valueOf(request.getByteData().length)); urlConnection.setFixedLengthStreamingMode(request.getByteData().length); cachedBytesLenght = lengthWrapper[0]; urlConnection.setRequestProperty("Content-Length", String.valueOf(cachedBytesLenght)); urlConnection.setFixedLengthStreamingMode(cachedBytesLenght); String formBody = AsyncHttpProviderUtils.urlEncodeFormParams0(request.getFormParams()).toString(); urlConnection.setRequestProperty("Content-Length", String.valueOf(formBody.length())); urlConnection.setFixedLengthStreamingMode(formBody.length()); if (lenght != -1) { urlConnection.setRequestProperty("Content-Length", String.valueOf(lenght)); urlConnection.setFixedLengthStreamingMode(lenght); urlConnection.setFixedLengthStreamingMode((int) file.length()); urlConnection.setFixedLengthStreamingMode(length);
String query = "string=test"; URL url = new URL("http://myserver.com/myendpoint"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Accept-Charset", "UTF-8"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); connection.setFixedLengthStreamingMode(query.getBytes("UTF-8").length); OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); out.write(query);
private void postMessage(String uri, String contentType, byte[] bytes) throws IOException { final HttpURLConnection conn = (HttpURLConnection) new URL(uri).openConnection(); conn.setConnectTimeout(timeout); conn.setReadTimeout(timeout); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setFixedLengthStreamingMode(bytes.length); conn.setRequestProperty("Content-Type", contentType); final OutputStream os = conn.getOutputStream(); os.write(bytes); os.flush(); os.close(); }
URL url = new URL( Configuration.loggingURL ); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json; charset=utf-8"); conn.setRequestProperty("Content-Length", Integer.toString( json.toString().length() )); conn.setFixedLengthStreamingMode( json.toString().length() ); conn.setUseCaches(false); conn.connect(); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write( json.toString() ); writer.flush(); conn.disconnect();
// set up URL connection URL urlToRequest = new URL(urlStr); HttpURLConnection urlConnection = (HttpURLConnection)urlToRequest.openConnection(); urlConnection.setDoOutput(true); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // write out form parameters String postParamaters = "param1=value1¶m2=value2" urlConnection.setFixedLengthStreamingMode(postParameters.getBytes().length); PrintWriter out = new PrintWriter(urlConnection.getOutputStream()); out.print(postParameters); out.close(); // connect urlConnection.connect();
/** * Sets HTTP headers for connection. * * @param connection connection */ public void setHttpHeaders(HttpURLConnection connection) throws ProtocolException { connection.setRequestMethod("POST"); connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, contentType); connection.setFixedLengthStreamingMode(size()); }
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); conn.setFixedLengthStreamingMode(params.getBytes().length); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(params); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) { response += (inStream.nextLine()); }
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); //not using the .setRequestProperty to the length, but this, solves the problem that i've mentioned conn.setFixedLengthStreamingMode(params.getBytes().length); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(params); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) { response += (inStream.nextLine()); }
URL url = new URL("http://your.url.here:yourPortNumber/something"); HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection(); httpUrlConnection.setDoInput(true); httpUrlConnection.setDoOutput(true); httpUrlConnection.setRequestProperty("Content-Type", "application/octet-stream"); httpUrlConnection.setRequestMethod("POST"); httpUrlConnection.setFixedLengthStreamingMode(bytes.length); httpUrlConnection.connect(); httpUrlConnection.getOutputStream().write(bytes); httpUrlConnection.getOutputStream().flush(); if (httpsUrlConnection.getResponseCode() == 200) //OK { System.out.println("successfully uploaded data"); } httpUrlConnection.disconnect();
//this is your request-body, as byte-array byte[] body; URL url = new URL("https://android.googleapis.com/gcm/send"); Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy-host.com", 3128)); URLConnection con = url.openConnection(proxy); HttpURLConnection con1 = (HttpURLConnection) con; con1.setRequestMethod("POST"); con1.setRequestProperty("Content-type", "application/json"); con1.setDoOutput(true); con1.setUseCaches(false); con1.setFixedLengthStreamingMode(body.length); OutputStream out = con1.getOutputStream(); try { out.write(body); } finally { out.close(); }
URL url = new URL( address ); int len = params.getBytes().length; HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches( false ); // conn.setDoInput( true ); // input channel needed? conn.setDoOutput( true ); conn.setInstanceFollowRedirects( false ); conn.setRequestMethod( "POST" ); conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" ); conn.setRequestProperty( "charset", "utf-8" ); conn.setRequestProperty( "Content-Length", "" + Integer.toString( len ) ); conn.setFixedLengthStreamingMode( len ); DataOutputStream dos = new DataOutputStream( conn.getOutputStream() ); dos.writeBytes( params ); dos.flush(); dos.close(); conn.disconnect();
@Override protected String doInBackground(String... params) { try { URL url = new URL(Constants.USUARIO + "/createUsuario"); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); httpURLConnection.setFixedLengthStreamingMode(result.getBytes().length); httpURLConnection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); httpURLConnection.setRequestProperty("X-Requested-With", "XMLHttpRequest"); httpURLConnection.connect(); OutputStream os = new BufferedOutputStream(httpURLConnection.getOutputStream()); os.write(result.getBytes()); os.flush(); os = httpURLConnection.getOutputStream(); os.close(); httpURLConnection.disconnect(); } catch (Exception e) { Log.d("InputStream", e.getMessage()); }