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

How to use
setDoOutput
method
in
java.net.URLConnection

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

Refine searchRefine arrow

  • URL.openConnection
  • URL.<init>
  • URLConnection.getOutputStream
  • HttpURLConnection.setRequestMethod
  • URLConnection.getInputStream
  • 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: 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

URL url = new URL("http://www.google.com");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
String responseMsg = con.getResponseMessage();
int response = con.getResponseCode();
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

 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: 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: googleapis/google-cloud-java

@Test
public void testPostSignedUrl() throws IOException {
 if (storage.getOptions().getCredentials() != null) {
  assumeTrue(storage.getOptions().getCredentials() instanceof ServiceAccountSigner);
 }
 String blobName = "test-post-signed-url-blob";
 BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
 assertNotNull(storage.create(blob));
 URL url =
   storage.signUrl(blob, 1, TimeUnit.HOURS, Storage.SignUrlOption.httpMethod(HttpMethod.POST));
 URLConnection connection = url.openConnection();
 connection.setDoOutput(true);
 connection.connect();
 Blob remoteBlob = storage.get(BUCKET, blobName);
 assertNotNull(remoteBlob);
 assertEquals(blob.getBucket(), remoteBlob.getBucket());
 assertEquals(blob.getName(), remoteBlob.getName());
}
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

 URL url = new URL("http://www.example.com/resource");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestProperty(
  "Content-Type", "application/x-www-form-urlencoded" );
httpCon.setRequestMethod("DELETE");
httpCon.connect();
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

 HttpURLConnection httpUrlConnection = null;
URL url = new URL("http://example.com/server.cgi");
httpUrlConnection = (HttpURLConnection) url.openConnection();
httpUrlConnection.setUseCaches(false);
httpUrlConnection.setDoOutput(true);

httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.setRequestProperty("Connection", "Keep-Alive");
httpUrlConnection.setRequestProperty("Cache-Control", "no-cache");
httpUrlConnection.setRequestProperty(
  "Content-Type", "multipart/form-data;boundary=" + this.boundary);
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: 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

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

 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

 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

 URL url = new URL("http://www.example.com/login");
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection)con;
http.setRequestMethod("POST"); // PUT is another valid option
http.setDoOutput(true);
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();
java.netURLConnectionsetDoOutput

Javadoc

Sets the flag indicating whether this URLConnection allows output. It cannot be set after the connection is established.

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
  • getOutputStream
    Returns an output stream that writes to this connection.
  • 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
  • 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

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • putExtra (Intent)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Best IntelliJ plugins
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