Tabnine Logo
URLConnection.getOutputStream
Code IndexAdd Tabnine to your IDE (free)

How to use
getOutputStream
method
in
java.net.URLConnection

Best Java code snippets using java.net.URLConnection.getOutputStream (Showing top 20 results out of 11,178)

Refine searchRefine arrow

  • URL.openConnection
  • URL.<init>
  • URLConnection.setDoOutput
  • URLConnection.getInputStream
  • HttpURLConnection.setRequestMethod
  • URLConnection.setRequestProperty
origin: stackoverflow.com

 URLConnection connection = new URL(url).openConnection();
connection.setDoOutput(true); // Triggers POST.
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);

try (OutputStream output = connection.getOutputStream()) {
  output.write(query.getBytes(charset));
}

InputStream response = connection.getInputStream();
// ...
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);

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("firstParam", paramValue1));
params.add(new BasicNameValuePair("secondParam", paramValue2));
params.add(new BasicNameValuePair("thirdParam", paramValue3));

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

conn.connect();
origin: javax.activation/activation

/**
 * The getOutputStream method from the URL. First an attempt is
 * made to get the URLConnection object for the URL. If that
 * succeeds, the getOutputStream method on the URLConnection
 * is returned.
 *
 * @return the OutputStream.
 */
public OutputStream getOutputStream() throws IOException {
// get the url connection if it is available
url_conn = url.openConnection();

if (url_conn != null) {
  url_conn.setDoOutput(true);
  return url_conn.getOutputStream();
} else
  return null;
}
origin: stackoverflow.com

 OkHttpClient client = new OkHttpClient();
OutputStream out = null;
try {
  URL url = new URL("http://www.example.com");
  HttpURLConnection connection = client.open(url);
  for (Map.Entry<String, String> entry : multipart.getHeaders().entrySet()) {
    connection.addRequestProperty(entry.getKey(), entry.getValue());
  }
  connection.setRequestMethod("POST");
  // Write the request.
  out = connection.getOutputStream();
  multipart.writeBodyTo(out);
  out.close();

  // Read the response.
  if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
    throw new IOException("Unexpected HTTP response: "
        + connection.getResponseCode() + " " + connection.getResponseMessage());
  }
} finally {
  // Clean up.
  try {
    if (out != null) out.close();
  } catch (Exception e) {
  }
}
origin: stackoverflow.com

 HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");

FileBody fileBody = new FileBody(new File(fileName));
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.STRICT);
multipartEntity.addPart("file", fileBody);

connection.setRequestProperty("Content-Type", multipartEntity.getContentType().getValue());
OutputStream out = connection.getOutputStream();
try {
  multipartEntity.writeTo(out);
} finally {
  out.close();
}
int status = connection.getResponseCode();
...
origin: stackoverflow.com

 URL url = new URL("http://www.example.com/resource");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("PUT");
OutputStreamWriter out = new OutputStreamWriter(
  httpCon.getOutputStream());
out.write("Resource content");
out.close();
httpCon.getInputStream();
origin: xalan/xalan

    url = new URL(systemId);
_tohFactory.setOutputStream(
  _ostream = new FileOutputStream(url.getFile()));
    url = new URL(systemId);
    final URLConnection connection = url.openConnection();
_tohFactory.setOutputStream(_ostream = connection.getOutputStream());
return _tohFactory.getSerializationHandler();
origin: geoserver/geoserver

static OutputStream output(URL url, Resource configDir) throws IOException {
  // check for file url
  if ("file".equalsIgnoreCase(url.getProtocol())) {
    File f = URLs.urlToFile(url);
    if (!f.isAbsolute()) {
      // make relative to config dir
      return configDir.get(f.getPath()).out();
    } else {
      return new FileOutputStream(f);
    }
  } else {
    URLConnection cx = url.openConnection();
    cx.setDoOutput(true);
    return cx.getOutputStream();
  }
}
origin: geotools/geotools

/**
 * @see org.geotools.data.ows.HTTPClient#post(java.net.URL, java.io.InputStream,
 *     java.lang.String)
 */
public HTTPResponse post(
    final URL url, final InputStream postContent, final String postContentType)
    throws IOException {
  URLConnection connection = openConnection(url);
  if (connection instanceof HttpURLConnection) {
    ((HttpURLConnection) connection).setRequestMethod("POST");
  }
  connection.setDoOutput(true);
  if (postContentType != null) {
    connection.setRequestProperty("Content-type", postContentType);
  }
  connection.connect();
  OutputStream outputStream = connection.getOutputStream();
  try {
    byte[] buff = new byte[512];
    int count;
    while ((count = postContent.read(buff)) > -1) {
      outputStream.write(buff, 0, count);
    }
  } finally {
    outputStream.flush();
    outputStream.close();
  }
  return new SimpleHTTPResponse(connection);
}
origin: stackoverflow.com

URLConnection connection = new URL(url).openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
  OutputStream output = connection.getOutputStream();
  PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
) {
origin: javax.xml.bind/jaxb-api

URLConnection con = url.openConnection();
con.setDoOutput(true);
con.setDoInput(false);
con.connect();
return new StreamResult(con.getOutputStream());
origin: stackoverflow.com

 public class a {
  public static void main(String [] a) throws Exception {
   java.net.URLConnection c = new java.net.URL("https://mydomain.com/").openConnection();
   c.setDoOutput(true);
   c.getOutputStream();
  }
}
origin: stackoverflow.com

 String urlParameters  = "param1=a&param2=b&param3=c";
byte[] postData       = urlParameters.getBytes( StandardCharsets.UTF_8 );
int    postDataLength = postData.length;
String request        = "http://example.com/index.php";
URL    url            = new URL( request );
HttpURLConnection conn= (HttpURLConnection) url.openConnection();           
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( postDataLength ));
conn.setUseCaches( false );
try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
  wr.write( postData );
}
origin: stackoverflow.com

 public class a {
  public static void main(String [] a) throws Exception {
   java.net.URLConnection c = new java.net.URL("https://google.com/").openConnection();
   c.setDoOutput(true);
   c.getOutputStream();
  }
}
origin: stackoverflow.com

 String rawData = "id=10";
String type = "application/x-www-form-urlencoded";
String encodedData = URLEncoder.encode( rawData ); 
URL u = new URL("http://www.example.com/page.php");
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty( "Content-Type", type );
conn.setRequestProperty( "Content-Length", String.valueOf(encodedData.length()));
OutputStream os = conn.getOutputStream();
os.write(encodedData.getBytes());
origin: stackoverflow.com

 HttpURLConnection con = (HttpURLConnection) new URL("https://www.example.com").openConnection();
con.setRequestMethod("POST");
con.getOutputStream().write("LOGIN".getBytes("UTF-8"));
con.getInputStream();
origin: stackoverflow.com

 HttpURLConnection httpcon = (HttpURLConnection) ((new URL("a url").openConnection()));
httpcon.setDoOutput(true);
httpcon.setRequestProperty("Content-Type", "application/json");
httpcon.setRequestProperty("Accept", "application/json");
httpcon.setRequestMethod("POST");
httpcon.connect();

byte[] outputBytes = "{'value': 7.5}".getBytes("UTF-8");
OutputStream os = httpcon.getOutputStream();
os.write(outputBytes);

os.close();
origin: stackoverflow.com

 URL url = new URL("http://www.example.com/resource");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("PUT");
OutputStreamWriter out = new OutputStreamWriter(
  httpCon.getOutputStream());
out.write("Data you want to put");
out.close();
origin: stackoverflow.com

 String urlParameters = "param1=a&param2=b&param3=c";
URL url = new URL("http://example.com/index.php");
URLConnection conn = url.openConnection();

conn.setDoOutput(true);

OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());

writer.write(urlParameters);
writer.flush();

String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

while ((line = reader.readLine()) != null) {
  System.out.println(line);
}
writer.close();
reader.close();
origin: stackoverflow.com

URL u = new URL("http://www.example.com/"); 
 HttpURLConnection huc = (HttpURLConnection)u.openConnection(); 
 huc.setRequestMethod("GET"); 
 huc.connect() ; 
 OutputStream os = huc.getOutputStream(); 
 int code = huc.getResponseCode();
java.netURLConnectiongetOutputStream

Javadoc

Returns an OutputStream for writing data to this URLConnection. It throws an UnknownServiceException by default. This method must be overridden by its subclasses.

Popular methods of URLConnection

  • getInputStream
    Returns an input stream that reads from this open connection. A SocketTimeoutException can be thrown
  • setUseCaches
    Sets the value of the useCaches field of thisURLConnection to the specified value. Some protocols do
  • connect
    Opens a communications link to the resource referenced by this URL, if such a connection has not alr
  • setRequestProperty
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • getLastModified
    Returns the value of the last-modified header field. The result is the number of milliseconds since
  • setConnectTimeout
    Sets a specified timeout value, in milliseconds, to be used when opening a communications link to th
  • setDoOutput
    Sets the value of the doOutput field for thisURLConnection to the specified value. A URL connection
  • getContentLength
    Returns the value of the content-length header field.Note: #getContentLengthLong()should be preferre
  • setReadTimeout
    Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeou
  • getContentType
    Returns the value of the content-type header field.
  • getHeaderField
    Returns the value of the named header field. If called on a connection that sets the same header mul
  • setDoInput
    Sets the value of the doInput field for thisURLConnection to the specified value. A URL connection c
  • getHeaderField,
  • setDoInput,
  • addRequestProperty,
  • getURL,
  • getContentEncoding,
  • guessContentTypeFromName,
  • setDefaultUseCaches,
  • getFileNameMap,
  • getContent

Popular in Java

  • Creating JSON documents from java classes using gson
  • getExternalFilesDir (Context)
  • findViewById (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Runner (org.openjdk.jmh.runner)
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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