javax.net.ssl.HttpsURLConnection.getOutputStream()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(217)

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

HttpsURLConnection.getOutputStream介绍

暂无

代码示例

代码示例来源:origin: jmdhappy/xxpay-master

conn.setRequestMethod(requestMethod);
if (null != outputStr) {
  OutputStream outputStream = conn.getOutputStream();
  outputStream.write(outputStr.getBytes("UTF-8"));
  outputStream.close();

代码示例来源:origin: jmdhappy/xxpay-master

conn.setRequestMethod(requestMethod);
if (null != outputStr) {
  OutputStream outputStream = conn.getOutputStream();
  outputStream.write(outputStr.getBytes("UTF-8"));
  outputStream.close();

代码示例来源:origin: Javen205/IJPay

conn.connect();
out = conn.getOutputStream();
out.write(data.getBytes(Charsets.UTF_8));
out.flush();

代码示例来源:origin: Javen205/IJPay

conn.connect();
out = conn.getOutputStream();
out.write(data.getBytes(Charsets.UTF_8));
out.flush();

代码示例来源:origin: GlowstoneMC/Glowstone

try (DataOutputStream os = new DataOutputStream(conn.getOutputStream())) {
  os.writeBytes(JSONValue.toJSONString(playerList));

代码示例来源:origin: jberkel/sms-backup-plus

private HttpsURLConnection postTokenEndpoint(String payload) throws IOException {
  HttpsURLConnection connection = (HttpsURLConnection) new URL(TOKEN_URL).openConnection();
  connection.setDoOutput(true);
  connection.setRequestMethod("POST");
  connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  final OutputStream os = connection.getOutputStream();
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
  writer.write(payload);
  writer.flush();
  writer.close();
  os.close();
  return connection;
}

代码示例来源:origin: com.microsoft.azure.iothub-java-client/iothub-java-device-client

/**
 * Sends the request to the URL given in the constructor.
 *
 * @throws IOException if the connection could not be established, or the
 * server responded with a bad status code.
 */
public void connect() throws IOException
{
  // Codes_SRS_HTTPSCONNECTION_11_004: [The function shall stream the request body, if present, through the connection.]
  if (this.body.length > 0)
  {
    this.connection.setDoOutput(true);
    this.connection.getOutputStream().write(this.body);
  }
  // Codes_SRS_HTTPSCONNECTION_11_003: [The function shall send a request to the URL given in the constructor.]
  // Codes_SRS_HTTPSCONNECTION_11_005: [The function shall throw an IOException if the connection could not be established, or the server responded with a bad status code.]
  this.connection.connect();
}

代码示例来源:origin: mockito/shipkit

private String doRequest(String relativeUrl, String method, Optional<String> body) throws IOException {
  URL url = new URL(gitHubApiUrl + relativeUrl);
  HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
  conn.setRequestMethod(method);
  conn.setDoOutput(true);
  conn.setRequestProperty("Content-Type", "application/json");
  conn.setRequestProperty("Authorization", "token " + authToken);
  if (body.isPresent()) {
    try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
      wr.writeBytes(body.get());
      wr.flush();
    }
  }
  return call(method, conn);
}

代码示例来源:origin: Azure/azure-iot-sdk-java

/**
 * Sends the request to the URL given in the constructor.
 *
 * @throws IOException This exception thrown if the connection could not be established,
 * or the server responded with a bad status code.
 */
public void connect() throws IOException
{
  // Codes_SRS_HTTPCONNECTION_25_006: [The function shall stream the request body, if present, through the connection.]
  if (this.body.length > 0)
  {
    this.connection.setDoOutput(true);
    this.connection.getOutputStream().write(this.body);
  }
  // Codes_SRS_HTTPCONNECTION_25_005: [The function shall send a request to the URL given in the constructor.]
  // Codes_SRS_HTTPCONNECTION_25_007: [The function shall throw an IOException if the connection could not be established, or the server responded with a bad status code.]
  this.connection.connect();
}

代码示例来源:origin: org.shipkit/shipkit

private String doRequest(String relativeUrl, String method, Optional<String> body) throws IOException {
  URL url = new URL(gitHubApiUrl + relativeUrl);
  HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
  conn.setRequestMethod(method);
  conn.setDoOutput(true);
  conn.setRequestProperty("Content-Type", "application/json");
  conn.setRequestProperty("Authorization", "token " + authToken);
  if (body.isPresent()) {
    try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
      wr.writeBytes(body.get());
      wr.flush();
    }
  }
  return call(method, conn);
}

代码示例来源:origin: org.talend.components/components-marketo-runtime

public RequestResult executePostRequest(Class<?> resultClass, JsonObject inputJson) throws MarketoException {
  try {
    URL url = new URL(current_uri.toString());
    HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
    urlConn.setRequestMethod(QUERY_METHOD_POST);
    urlConn.setRequestProperty(REQUEST_PROPERTY_CONTENT_TYPE, REQUEST_VALUE_APPLICATION_JSON);
    urlConn.setRequestProperty(REQUEST_PROPERTY_ACCEPT, REQUEST_VALUE_TEXT_JSON);
    urlConn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
    wr.write(inputJson.toString());
    wr.flush();
    wr.close();
    return (RequestResult) new Gson().fromJson(getReaderFromHttpResponse(urlConn), resultClass);
  } catch (IOException e) {
    LOG.error("GET request failed: {}", e.getMessage());
    throw new MarketoException(REST, e.getMessage());
  }
}

代码示例来源:origin: Azure/azure-iot-sdk-java

/**
 * Sends the request to the URL given in the constructor.
 *
 * @throws IOException This exception thrown if the connection could not be established,
 * or the server responded with a bad status code.
 */
public void connect() throws IOException
{
  // Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_006: [The function shall stream the request body, if present, through the connection.]
  if (this.body.length > 0)
  {
    this.connection.setDoOutput(true);
    this.connection.getOutputStream().write(this.body);
  }
  // Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_005: [The function shall send a request to the URL given in the constructor.]
  // Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_007: [The function shall throw an IOException if the connection could not be established, or the server responded with a bad status code.]
  this.connection.connect();
}

代码示例来源:origin: Talend/components

public RequestResult executePostRequest(Class<?> resultClass, JsonObject inputJson) throws MarketoException {
  try {
    URL url = new URL(current_uri.toString());
    HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
    urlConn.setRequestMethod(QUERY_METHOD_POST);
    urlConn.setRequestProperty(REQUEST_PROPERTY_CONTENT_TYPE, REQUEST_VALUE_APPLICATION_JSON);
    urlConn.setRequestProperty(REQUEST_PROPERTY_ACCEPT, REQUEST_VALUE_TEXT_JSON);
    urlConn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
    wr.write(inputJson.toString());
    wr.flush();
    wr.close();
    return (RequestResult) new Gson().fromJson(getReaderFromHttpResponse(urlConn), resultClass);
  } catch (IOException e) {
    LOG.error("GET request failed: {}", e.getMessage());
    throw new MarketoException(REST, e.getMessage());
  }
}

代码示例来源:origin: com.microsoft.azure/adal4j

private static String executePostRequest(Logger log, String postData,
    Map<String, String> headers, HttpsURLConnection conn)
    throws IOException {
  configureAdditionalHeaders(conn, headers);
  conn.setRequestMethod("POST");
  conn.setDoOutput(true);
  DataOutputStream wr = null;
  try {
    wr = new DataOutputStream(conn.getOutputStream());
    wr.writeBytes(postData);
    wr.flush();
    return getResponse(log, headers, conn);
  }
  finally {
    if (wr != null) {
      wr.close();
    }
  }
}

代码示例来源:origin: AzureAD/azure-activedirectory-library-for-java

private static String executePostRequest(Logger log, String postData,
    Map<String, String> headers, HttpsURLConnection conn)
    throws IOException {
  configureAdditionalHeaders(conn, headers);
  conn.setRequestMethod("POST");
  conn.setDoOutput(true);
  DataOutputStream wr = null;
  try {
    wr = new DataOutputStream(conn.getOutputStream());
    wr.writeBytes(postData);
    wr.flush();
    return getResponse(log, headers, conn);
  }
  finally {
    if (wr != null) {
      wr.close();
    }
  }
}

代码示例来源:origin: net.roboconf/roboconf-iaas-azure

private int processPostRequest(URL url, byte[] data, String contentType, String keyStore, String keyStorePassword)
throws UnrecoverableKeyException, KeyManagementException, KeyStoreException, NoSuchAlgorithmException, IOException {
  SSLSocketFactory sslFactory = this.getSSLSocketFactory(keyStore, keyStorePassword);
  HttpsURLConnection con = null;
  con = (HttpsURLConnection) url.openConnection();
  con.setSSLSocketFactory(sslFactory);
  con.setDoOutput(true);
  con.setRequestMethod("POST");
  con.addRequestProperty("x-ms-version", "2014-04-01");
  con.setRequestProperty("Content-Length", String.valueOf(data.length));
  con.setRequestProperty("Content-Type", contentType);
  DataOutputStream  requestStream = new DataOutputStream (con.getOutputStream());
  requestStream.write(data);
  requestStream.flush();
  requestStream.close();
  return con.getResponseCode();
}

代码示例来源:origin: microg/AppleWifiNlpBackend

public Collection<Location> retrieveLocations(String... macs) throws IOException {
  Request request = createRequest(macs);
  byte[] byteb = request.toByteArray();
  byte[] bytes = combineBytes(APPLE_MAGIC_BYTES, byteb, (byte) byteb.length);
  HttpsURLConnection connection = createConnection();
  prepareConnection(connection, bytes.length);
  OutputStream out = connection.getOutputStream();
  out.write(bytes);
  out.flush();
  out.close();
  InputStream in = connection.getInputStream();
  in.skip(10);
  Response response = wire.parseFrom(readStreamToEnd(in), Response.class);
  in.close();
  Collection<Location> locations = new ArrayList<Location>();
  for (Response.ResponseWifi wifi : response.wifis) {
    locations.add(fromResponseWifi(wifi));
  }
  return locations;
}

代码示例来源:origin: line/line-sdk-android

@Before
public void setup() throws Exception {
  MockitoAnnotations.initMocks(this);
  target = spy(new ChannelServiceHttpClient(userAgentGenerator));
  target.setConnectTimeoutMillis(CONNECT_TIMEOUT_MILLIS);
  target.setReadTimeoutMillis(READ_TIMEOUT_MILLIS);
  doReturn(httpsURLConnection).when(target).openHttpConnection(any(Uri.class));
  connectionOutputStream = new ByteArrayOutputStream();
  doReturn(connectionOutputStream).when(httpsURLConnection).getOutputStream();
  doReturn(USER_AGENT).when(userAgentGenerator).getUserAgent();
}

代码示例来源:origin: apache/jackrabbit-oak

protected void doHttpsUpload(InputStream in, long contentLength, URI uri) throws IOException {
  HttpsURLConnection conn = getHttpsConnection(contentLength, uri);
  IOUtils.copy(in, conn.getOutputStream());
  int responseCode = conn.getResponseCode();
  assertTrue(conn.getResponseMessage(), responseCode < 400);
}

代码示例来源:origin: apache/jackrabbit-oak

protected void doHttpsUpload(InputStream in, long contentLength, URI uri) throws IOException {
    HttpsURLConnection conn = getHttpsConnection(contentLength, uri);
    IOUtils.copy(in, conn.getOutputStream());
    int responseCode = conn.getResponseCode();
    assertTrue(conn.getResponseMessage(), responseCode < 400);
  }
}

相关文章

HttpsURLConnection类方法