Tabnine Logo
HttpURLConnection.setDoInput
Code IndexAdd Tabnine to your IDE (free)

How to use
setDoInput
method
in
java.net.HttpURLConnection

Best Java code snippets using java.net.HttpURLConnection.setDoInput (Showing top 20 results out of 6,030)

Refine searchRefine arrow

  • HttpURLConnection.setDoOutput
  • HttpURLConnection.setRequestMethod
  • HttpURLConnection.setRequestProperty
  • URL.openConnection
  • HttpURLConnection.getOutputStream
  • URL.<init>
origin: nutzam/nutz

protected void setupDoInputOutputFlag() {
  conn.setDoInput(true);
  conn.setDoOutput(true);
}
origin: spring-projects/spring-framework

/**
 * Template method for preparing the given {@link HttpURLConnection}.
 * <p>The default implementation prepares the connection for input and output, and sets the HTTP method.
 * @param connection the connection to prepare
 * @param httpMethod the HTTP request method ({@code GET}, {@code POST}, etc.)
 * @throws IOException in case of I/O errors
 */
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
  if (this.connectTimeout >= 0) {
    connection.setConnectTimeout(this.connectTimeout);
  }
  if (this.readTimeout >= 0) {
    connection.setReadTimeout(this.readTimeout);
  }
  connection.setDoInput(true);
  if ("GET".equals(httpMethod)) {
    connection.setInstanceFollowRedirects(true);
  }
  else {
    connection.setInstanceFollowRedirects(false);
  }
  if ("POST".equals(httpMethod) || "PUT".equals(httpMethod) ||
      "PATCH".equals(httpMethod) || "DELETE".equals(httpMethod)) {
    connection.setDoOutput(true);
  }
  else {
    connection.setDoOutput(false);
  }
  connection.setRequestMethod(httpMethod);
}
origin: spotify/helios

 private HttpURLConnection post(final String path, final byte[] body) throws IOException {
  final URL url = new URL(masterEndpoint() + path);
  final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setRequestMethod("POST");
  connection.setRequestProperty("Content-Type", "application/json");
  connection.setDoInput(true);
  connection.setDoOutput(true);
  connection.getOutputStream().write(body);
  return connection;
 }
}
origin: cymcsg/UltimateAndroid

public static Bitmap returnBitMap(String url) {
  URL myFileUrl = null;
  Bitmap bitmap = null;
  try {
    myFileUrl = new URL(url);
  } catch (MalformedURLException e) {
    e.printStackTrace();
  }
  try {
    HttpURLConnection conn = (HttpURLConnection) myFileUrl
        .openConnection();
    conn.setDoInput(true);
    conn.connect();
    InputStream is = conn.getInputStream();
    bitmap = BitmapFactory.decodeStream(is);
    is.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return bitmap;
}
origin: jmdhappy/xxpay-master

/**
 * 设置http请求默认属性
 *
 * @param httpConnection
 */
protected void setHttpRequest(HttpURLConnection httpConnection) {
  //设置连接超时时间
  httpConnection.setConnectTimeout(this.timeOut * 1000);
  //User-Agent
  httpConnection.setRequestProperty("User-Agent",
      HttpClient.USER_AGENT_VALUE);
  //不使用缓存
  httpConnection.setUseCaches(false);
  //允许输入输出
  httpConnection.setDoInput(true);
  httpConnection.setDoOutput(true);
}
origin: jmxtrans/jmxtrans

public void configure(HttpURLConnection httpURLConnection) throws ProtocolException {
  httpURLConnection.setRequestMethod(requestMethod);
  httpURLConnection.setDoInput(true);
  httpURLConnection.setDoOutput(true);
  httpURLConnection.setReadTimeout(readTimeoutInMillis);
  if (contentType != null) httpURLConnection.setRequestProperty("Content-Type", contentType);
  if (authorization != null) httpURLConnection.setRequestProperty("Authorization", authorization);
  httpURLConnection.setRequestProperty("User-Agent", userAgent);
}
origin: facebook/facebook-android-sdk

  @Override
  public void run() {
    try {
      HttpURLConnection connection =
          (HttpURLConnection) new java.net.URL(url).openConnection();
      connection.setDoInput(true);
      connection.connect();
      InputStream input = connection.getInputStream();
      Bitmap bitmap = BitmapFactory.decodeStream(input);
      Listener listener = listenerWeakReference.get();
      if (listener != null) {
        listener.onBitmapDownloadSuccess(url, bitmap);
      }
    } catch (Throwable t) {
      t.printStackTrace();
      Listener listener = listenerWeakReference.get();
      if (listener != null) {
        listener.onBitmapDownloadFailure(url);
      }
    }
  }
}
origin: org.springframework/spring-web

/**
 * Template method for preparing the given {@link HttpURLConnection}.
 * <p>The default implementation prepares the connection for input and output, and sets the HTTP method.
 * @param connection the connection to prepare
 * @param httpMethod the HTTP request method ({@code GET}, {@code POST}, etc.)
 * @throws IOException in case of I/O errors
 */
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
  if (this.connectTimeout >= 0) {
    connection.setConnectTimeout(this.connectTimeout);
  }
  if (this.readTimeout >= 0) {
    connection.setReadTimeout(this.readTimeout);
  }
  connection.setDoInput(true);
  if ("GET".equals(httpMethod)) {
    connection.setInstanceFollowRedirects(true);
  }
  else {
    connection.setInstanceFollowRedirects(false);
  }
  if ("POST".equals(httpMethod) || "PUT".equals(httpMethod) ||
      "PATCH".equals(httpMethod) || "DELETE".equals(httpMethod)) {
    connection.setDoOutput(true);
  }
  else {
    connection.setDoOutput(false);
  }
  connection.setRequestMethod(httpMethod);
}
origin: libgdx/libgdx

/** Downloads the content of the specified url to the array. The array has to be big enough. */
private int download (byte[] out, String url) {
  InputStream in = null;
  try {
    HttpURLConnection conn = null;
    conn = (HttpURLConnection)new URL(url).openConnection();
    conn.setDoInput(true);
    conn.setDoOutput(false);
    conn.setUseCaches(true);
    conn.connect();
    in = conn.getInputStream();
    int readBytes = 0;
    while (true) {
      int length = in.read(out, readBytes, out.length - readBytes);
      if (length == -1) break;
      readBytes += length;
    }
    return readBytes;
  } catch (Exception ex) {
    return 0;
  } finally {
    StreamUtils.closeQuietly(in);
  }
}
origin: GitLqr/LQRWeChat

/**
 * 根据一个网络连接(String)获取bitmap图像
 *
 * @param imageUri
 * @return
 */
public static Bitmap getNetBitmap(String imageUri) {
  // 显示网络上的图片
  Bitmap bitmap = null;
  try {
    URL myFileUrl = new URL(imageUri);
    HttpURLConnection conn = (HttpURLConnection) myFileUrl
        .openConnection();
    conn.setDoInput(true);
    conn.connect();
    InputStream is = conn.getInputStream();
    bitmap = BitmapFactory.decodeStream(is);
    is.close();
  } catch (OutOfMemoryError e) {
    e.printStackTrace();
    bitmap = null;
  } catch (IOException e) {
    e.printStackTrace();
    bitmap = null;
  }
  return bitmap;
}
origin: looly/hutool

  this.conn.setRequestMethod(this.method.toString());
} catch (ProtocolException e) {
  throw new HttpException(e.getMessage(), e);
this.conn.setDoInput(true);
if (Method.POST.equals(this.method) || Method.PUT.equals(this.method) || Method.PATCH.equals(this.method) || Method.DELETE.equals(this.method)) {
  this.conn.setDoOutput(true);
  this.conn.setUseCaches(false);
origin: alipay/sofa-rpc

private HttpURLConnection createConnection(URL url, String method, boolean doOutput) {
  HttpURLConnection con;
  try {
    con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod(method);
    con.setConnectTimeout(connectTimeout);
    con.setReadTimeout(readTimeout);
    con.setDoOutput(doOutput);
    con.setDoInput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type", "text/plain");
    return con;
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
}
origin: qunarcorp/qmq

HttpURLConnection connection = null;
try {
  connection = (HttpURLConnection) (new URL(metaServerEndpoint).openConnection());
  connection.setConnectTimeout(1000);
  connection.setReadTimeout(500);
  connection.setDoInput(true);
  in = new InputStreamReader(connection.getInputStream());
  String content = CharStreams.toString(in);
origin: looly/hutool

  this.conn.setRequestMethod(this.method.toString());
} catch (ProtocolException e) {
  throw new HttpException(e.getMessage(), e);
this.conn.setDoInput(true);
if (Method.POST.equals(this.method) || Method.PUT.equals(this.method) || Method.PATCH.equals(this.method) || Method.DELETE.equals(this.method)) {
  this.conn.setDoOutput(true);
  this.conn.setUseCaches(false);
origin: alipay/sofa-rpc

private HttpURLConnection createConnection(URL url, String method, boolean doOutput) {
  HttpURLConnection con;
  try {
    con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod(method);
    con.setConnectTimeout(connectTimeout);
    con.setReadTimeout(readTimeout);
    con.setDoOutput(doOutput);
    con.setDoInput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type", "text/plain");
    return con;
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
}
origin: ethereum/ethereumj

private String postQuery(String endPoint, String json) throws IOException {
  URL url = new URL(endPoint);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setConnectTimeout(5000);
  conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
  conn.setDoOutput(true);
  conn.setDoInput(true);
  conn.setRequestMethod("POST");
  OutputStream os = conn.getOutputStream();
  os.write(json.getBytes("UTF-8"));
  os.close();
  // read the response
  InputStream in = new BufferedInputStream(conn.getInputStream());
  String result = null;
  try (Scanner scanner = new Scanner(in, "UTF-8")) {
    result =  scanner.useDelimiter("\\A").next();
  }
  in.close();
  conn.disconnect();
  return result;
}
origin: jfinal/jfinal

private static HttpURLConnection getHttpConnection(String url, String method, Map<String, String> headers) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
  URL _url = new URL(url);
  HttpURLConnection conn = (HttpURLConnection)_url.openConnection();
  if (conn instanceof HttpsURLConnection) {
    ((HttpsURLConnection)conn).setSSLSocketFactory(sslSocketFactory);
    ((HttpsURLConnection)conn).setHostnameVerifier(trustAnyHostnameVerifier);
  }
  
  conn.setRequestMethod(method);
  conn.setDoOutput(true);
  conn.setDoInput(true);
  
  conn.setConnectTimeout(19000);
  conn.setReadTimeout(19000);
  
  conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
  conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36");
  
  if (headers != null && !headers.isEmpty()) {
    for (Entry<String, String> entry : headers.entrySet()) {
      conn.setRequestProperty(entry.getKey(), entry.getValue());
    }
  }
  
  return conn;
}
 
origin: graphhopper/graphhopper

public HttpURLConnection createConnection(String urlStr) throws IOException {
  URL url = new URL(urlStr);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  // Will yield in a POST request: conn.setDoOutput(true);
  conn.setDoInput(true);
  conn.setUseCaches(true);
  conn.setRequestProperty("Referrer", referrer);
  conn.setRequestProperty("User-Agent", userAgent);
  // suggest respond to be gzipped or deflated (which is just another compression)
  // http://stackoverflow.com/q/3932117
  conn.setRequestProperty("Accept-Encoding", acceptEncoding);
  conn.setReadTimeout(timeout);
  conn.setConnectTimeout(timeout);
  return conn;
}
origin: apache/flume

 /**
  * Creates an HTTP connection to the configured endpoint address. This
  * connection is setup for a POST request, and uses the content type and
  * accept header values in the configuration.
  *
  * @return the connection object
  * @throws IOException on any connection error
  */
 public HttpURLConnection getConnection() throws IOException {
  HttpURLConnection connection = (HttpURLConnection)
    endpointUrl.openConnection();
  connection.setRequestMethod("POST");
  connection.setRequestProperty("Content-Type", contentTypeHeader);
  connection.setRequestProperty("Accept", acceptHeader);
  connection.setConnectTimeout(connectTimeout);
  connection.setReadTimeout(requestTimeout);
  connection.setDoOutput(true);
  connection.setDoInput(true);
  connection.connect();
  return connection;
 }
}
origin: Javen205/IJPay

private static HttpURLConnection getHttpConnection(String url, String method, Map<String, String> headers) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
  URL _url = new URL(url);
  HttpURLConnection conn = (HttpURLConnection)_url.openConnection();
  if (conn instanceof HttpsURLConnection) {
    ((HttpsURLConnection)conn).setSSLSocketFactory(sslSocketFactory);
    ((HttpsURLConnection)conn).setHostnameVerifier(trustAnyHostnameVerifier);
  }
  
  conn.setRequestMethod(method);
  conn.setDoOutput(true);
  conn.setDoInput(true);
  
  conn.setConnectTimeout(19000);
  conn.setReadTimeout(19000);
  
  conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
  conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36");
  
  if (headers != null && !headers.isEmpty())
    for (Entry<String, String> entry : headers.entrySet())
      conn.setRequestProperty(entry.getKey(), entry.getValue());
  
  return conn;
}

java.netHttpURLConnectionsetDoInput

Popular methods of HttpURLConnection

  • getInputStream
  • getResponseCode
    Returns the response code returned by the remote HTTP server.
  • setRequestMethod
    Sets the request command which will be sent to the remote HTTP server. This method can only be calle
  • setRequestProperty
  • setDoOutput
  • getOutputStream
  • disconnect
    Releases this connection so that its resources may be either reused or closed. Unlike other Java imp
  • setConnectTimeout
  • connect
  • setReadTimeout
  • getErrorStream
    Returns an input stream from the server in the case of an error such as the requested file has not b
  • getResponseMessage
    Returns the response message returned by the remote HTTP server.
  • getErrorStream,
  • getResponseMessage,
  • getHeaderField,
  • setUseCaches,
  • setInstanceFollowRedirects,
  • getHeaderFields,
  • addRequestProperty,
  • getContentLength,
  • getURL

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getContentResolver (Context)
  • getSharedPreferences (Context)
  • getApplicationContext (Context)
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • JButton (javax.swing)
  • Runner (org.openjdk.jmh.runner)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now