java.net.URLConnection.setDoInput()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(147)

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

URLConnection.setDoInput介绍

[英]Sets the flag indicating whether this URLConnection allows input. It cannot be set after the connection is established.
[中]设置指示此URLConnection是否允许输入的标志。连接建立后无法设置。

代码示例

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

URL url = new URL(user_image_url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();   
conn.setDoInput(true);   
conn.connect();     
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);

代码示例来源:origin: jphp-group/jphp

public URLConnection getURLConnection() throws IOException {
  if (urlConnection == null) {
    if (proxy != null) {
      urlConnection = url.openConnection(proxy);
    } else {
      urlConnection = url.openConnection();
    }
    urlConnection.setDoInput(false);
    urlConnection.setDoOutput(false);
    if (getMode().startsWith("r") || getMode().startsWith("w") || getMode().startsWith("a")) {
      urlConnection.setDoInput(true);
    }
    if (getMode().startsWith("w") || getMode().startsWith("a")) {
      urlConnection.setDoOutput(true);
    }
  }
  return urlConnection;
}

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

URL myURL = new URL(serviceURL);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
String userCredentials = "username:password";
String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes()));
myURLConnection.setRequestProperty ("Authorization", basicAuth);
myURLConnection.setRequestMethod("POST");
myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
myURLConnection.setRequestProperty("Content-Length", "" + postData.getBytes().length);
myURLConnection.setRequestProperty("Content-Language", "en-US");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);

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

public static Bitmap getBitmapFromURL(String src) {
  try {
    URL url = new URL(src);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
    return myBitmap;
  } catch (IOException e) {
    // Log exception
    return null;
  }
}

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

URL url = new URL("http://yoururl.com");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);

Uri.Builder builder = new Uri.Builder()
    .appendQueryParameter("firstParam", paramValue1)
    .appendQueryParameter("secondParam", paramValue2)
    .appendQueryParameter("thirdParam", paramValue3);
String query = builder.build().getEncodedQuery();

OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
      new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();

conn.connect();

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

public Bitmap getBitmapFromURL(String strURL) {
  try {
    URL url = new URL(strURL);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
    return myBitmap;
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
}

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

public Bitmap getBitmapFromURL(String strURL) {
  try {
    URL url = new URL(strURL);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
    return myBitmap;
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
}

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

String response = "";
try {
  url = new URL(requestURL);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setReadTimeout(15000);
  conn.setConnectTimeout(15000);
  conn.setRequestMethod("POST");
  conn.setDoInput(true);
  conn.setDoOutput(true);
  OutputStream os = conn.getOutputStream();
  BufferedWriter writer = new BufferedWriter(
      new OutputStreamWriter(os, "UTF-8"));
    BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
    while ((line=br.readLine()) != null) {
      response+=line;

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

void ping() throws IOException
{
  pingCount++;
  Map<String, String> usageDataMap = collector.getUdcParams();
  StringBuilder uri = new StringBuilder( "http://" + address + "/" + "?" );
  for ( Map.Entry<String,String> entry : usageDataMap.entrySet() )
  {
    uri.append( entry.getKey() );
    uri.append( "=" );
    uri.append( URLEncoder.encode( entry.getValue(), StandardCharsets.UTF_8.name() ) );
    uri.append( "+" );
  }
  uri.append( PING + "=" ).append( pingCount );
  URL url = new URL( uri.toString() );
  URLConnection con = url.openConnection();
  con.setDoInput( true );
  con.setDoOutput( false );
  con.setUseCaches( false );
  con.connect();
  con.getInputStream().close();
}

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

public static Bitmap getBitmapFromURL(String src) {
  try {
    Log.e("src",src);
    URL url = new URL(src);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
    Log.e("Bitmap","returned");
    return myBitmap;
  } catch (IOException e) {
    e.printStackTrace();
    Log.e("Exception",e.getMessage());
    return null;
  }
}

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

public Bitmap getBitmapFromURL(String src) {
  try {
    java.net.URL url = new java.net.URL(src);
    HttpURLConnection connection = (HttpURLConnection) url
        .openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
    return myBitmap;
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
}

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

/**
 * Opens an InputStream for the given URL.
 */
/*package*/ static InputStream openUrl(String url) throws IOException {
  try {
    URLConnection urlConnection = new URL(url).openConnection();
    urlConnection.setConnectTimeout(TIMEOUT);
    urlConnection.setReadTimeout(TIMEOUT);
    urlConnection.setDoInput(true);
    urlConnection.setDoOutput(false);
    return urlConnection.getInputStream();
  } catch (Exception e) {
    IOException ioe = new IOException("Couldn't open " + url);
    ioe.initCause(e);
    throw ioe;
  }
}

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

URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream  input;
url = new URL (getCodeBase().toString() + "env.tcgi");
urlConn = url.openConnection();
urlConn.setDoInput (true);
urlConn.setDoOutput (true);
urlConn.setUseCaches (false);
urlConn.setRequestProperty("Content-Type","application/json");   
urlConn.setRequestProperty("Host", "android.schoolportal.gr");
urlConn.connect();  
//Create JSONObject here
JSONObject jsonParam = new JSONObject();
jsonParam.put("ID", "25");
jsonParam.put("description", "Real");
jsonParam.put("enable", "true");

代码示例来源:origin: jphp-group/jphp

@Signature
public static URLConnection create(String url, @Nullable Proxy proxy) throws IOException {
  URL _url = new URL(url);
  URLConnection urlConnection = proxy == null ? _url.openConnection() : _url.openConnection(proxy);
  urlConnection.setDoOutput(true);
  urlConnection.setDoInput(true);
  if (urlConnection instanceof HttpURLConnection) {
    HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
    httpURLConnection.setRequestMethod("GET");
  }
  return urlConnection;
}

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

URL url = new URL("http","www.google.com");
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
urlc.setAllowUserInteraction( false );
urlc.setDoInput( true );
urlc.setDoOutput( false );
urlc.setUseCaches( true );
urlc.setRequestMethod("GET");
urlc.connect();
// check you have received an status code 200 to indicate OK
// get the encoding from the Content-Type header
BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String line = null;
while((line = in.readLine()) != null) {
 System.out.println(line);
}

// close sockets, handle errors, etc.

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

String response = "";
try {
  url = new URL(requestURL);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setReadTimeout(15000);
  conn.setConnectTimeout(15000);
  conn.setRequestMethod("GET");
  conn.setDoInput(true);
  conn.setDoOutput(true);
  OutputStream os = conn.getOutputStream();
  BufferedWriter writer = new BufferedWriter(
      new OutputStreamWriter(os, "UTF-8"));
    BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
    while ((line=br.readLine()) != null) {
      response+=line;

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

@Override
    protected Void doInBackground(Void... params) {             
      try {
        URL myFileUrl = new URL("http://sposter.smartag.my/images/chicken_soup.jpg");
        HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();
        downloadBitmap = BitmapFactory.decodeStream(is);
              } catch (FileNotFoundException e) {             
        e.printStackTrace();
      }
      catch (IOException e) {         
        e.printStackTrace();
      }               
      return null;
    }

@Override
onPostExecute()
{
 ImageView image = (ImageView) findViewById(R.id.imview);            
      image.setImageBitmap(downloadBitmap);
}

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

public static String sendPostRequest(String requestUrl, String payload) {
  try {
    URL url = new URL(requestUrl);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Accept", "application/json");
    connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
    writer.write(payload);
    writer.close();
    BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    StringBuffer jsonString = new StringBuffer();
    String line;
    while ((line = br.readLine()) != null) {
        jsonString.append(line);
    }
    br.close();
    connection.disconnect();
  } catch (Exception e) {
      throw new RuntimeException(e.getMessage());
  }
  return jsonString.toString();
}

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

private StringBuffer request(String urlString) {
  // TODO Auto-generated method stub

  StringBuffer chaine = new StringBuffer("");
  try{
    URL url = new URL(urlString);
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setRequestProperty("User-Agent", "");
    connection.setRequestMethod("POST");
    connection.setDoInput(true);
    connection.connect();

    InputStream inputStream = connection.getInputStream();

    BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
    String line = "";
    while ((line = rd.readLine()) != null) {
      chaine.append(line);
    }
  }
  catch (IOException e) {
    // Writing exception to log
    e.printStackTrace();
  }
  return chaine;
}

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

protected Bitmap doInBackground(Void... params) {
  try {
    URL urlConnection = new URL(url);
    HttpURLConnection connection = (HttpURLConnection) urlConnection
        .openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
    return myBitmap;

相关文章

URLConnection类方法