Java HTTP Post writeToConnection(final HttpURLConnection couchdbConnection, final String content)

Here you can find the source of writeToConnection(final HttpURLConnection couchdbConnection, final String content)

Description

write To Connection

License

Open Source License

Declaration

public static void writeToConnection(final HttpURLConnection couchdbConnection, final String content) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.DataOutputStream;

import java.io.IOException;

import java.net.HttpURLConnection;

public class Main {
    public static void writeToConnection(final HttpURLConnection couchdbConnection, final String content) {
        try {/*from  w ww  . ja  va 2s. c o  m*/
            couchdbConnection.setDoOutput(true);
            final DataOutputStream dataOutputStream = new DataOutputStream(couchdbConnection.getOutputStream());
            dataOutputStream.writeBytes(content);
            dataOutputStream.flush();
            dataOutputStream.close();
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    public static void writeToConnection(final HttpURLConnection couchdbConnection, final byte[] content) {
        try {
            couchdbConnection.setDoOutput(true);
            final DataOutputStream dataOutputStream = new DataOutputStream(couchdbConnection.getOutputStream());
            dataOutputStream.write(content, 0, content.length);
            dataOutputStream.flush();
            dataOutputStream.close();
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
}

Related

  1. URLPost(String strUrl, Map map)
  2. writeBody(HttpURLConnection connection, String body)
  3. writeContent(HttpURLConnection urlConn, String content)
  4. writeFileFromUrl(URL sourceUrl, File targetFile)
  5. writeString(HttpURLConnection conn, String content, String charsetName)