java.net.HttpURLConnection.setFixedLengthStreamingMode()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中java.net.HttpURLConnection.setFixedLengthStreamingMode()方法的一些代码示例,展示了HttpURLConnection.setFixedLengthStreamingMode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpURLConnection.setFixedLengthStreamingMode()方法的具体详情如下:
包路径:java.net.HttpURLConnection
类名称:HttpURLConnection
方法名:setFixedLengthStreamingMode

HttpURLConnection.setFixedLengthStreamingMode介绍

[英]Equivalent to setFixedLengthStreamingMode((long) contentLength), but available on earlier versions of Android and limited to 2 GiB.
[中]相当于setFixedLengthStreamingMode((long)contentLength),但在早期版本的Android上可用,限制为2 GiB。

代码示例

代码示例来源:origin: igniterealtime/Smack

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()) {

代码示例来源:origin: wildfly/wildfly

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()) {

代码示例来源:origin: google/ExoPlayer

connection.setRequestMethod(DataSpec.getStringForHttpMethod(httpMethod));
if (httpBody != null) {
 connection.setFixedLengthStreamingMode(httpBody.length);
 connection.connect();
 OutputStream os = connection.getOutputStream();

代码示例来源:origin: yanzhenjie/NoHttp

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

代码示例来源:origin: jersey/jersey

setRequestMethodViaJreBugWorkaround(uc, httpMethod);
} else {
  uc.setRequestMethod(httpMethod);
        uc.setFixedLengthStreamingMode(request.getLength());
      } else {
        uc.setFixedLengthStreamingMode(length);

代码示例来源:origin: jersey/jersey

setRequestMethodViaJreBugWorkaround(uc, httpMethod);
} else {
  uc.setRequestMethod(httpMethod);
        uc.setFixedLengthStreamingMode(request.getLength());
      } else {
        uc.setFixedLengthStreamingMode(length);

代码示例来源:origin: org.glassfish.jersey.core/jersey-client

setRequestMethodViaJreBugWorkaround(uc, httpMethod);
} else {
  uc.setRequestMethod(httpMethod);
        uc.setFixedLengthStreamingMode(request.getLength());
      } else {
        uc.setFixedLengthStreamingMode(length);

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: com.ning/async-http-client

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: maricn/logback-slack-appender

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

// 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&param2=value2"
urlConnection.setFixedLengthStreamingMode(postParameters.getBytes().length);
PrintWriter out = new PrintWriter(urlConnection.getOutputStream());
out.print(postParameters);
out.close();

// connect
urlConnection.connect();

代码示例来源:origin: com.yandex.java/ym-java-epr-sdk

/**
 * 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());
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

相关文章

HttpURLConnection类方法