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

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

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

HttpsURLConnection.setRequestProperty介绍

暂无

代码示例

代码示例来源:origin: knowm/XChange

static ReturnCurrenciesResponse allCurrenciesStatic() throws IOException {
  HttpsURLConnection c =
    (HttpsURLConnection) new URL("https://api.idex.market/returnCurrencies").openConnection();
  c.setRequestMethod("POST");
  c.setRequestProperty("Accept-Encoding", "gzip");
  c.setRequestProperty("User-Agent", "irrelevant");
  try (InputStreamReader inputStreamReader =
    new InputStreamReader(new GZIPInputStream(c.getInputStream()))) {
   ObjectMapper objectMapper = new ObjectMapper();
   return objectMapper.readerFor(ReturnCurrenciesResponse.class).readValue(inputStreamReader);
  }
 }
}

代码示例来源:origin: knowm/XChange

/** same as curl -XPOST https://api.idex.market/returnTicker */
static ReturnTickerRequestedWithNull allTickersStatic() throws IOException {
 ReturnTickerRequestedWithNull o = null;
 javax.net.ssl.HttpsURLConnection c = null;
 c = (HttpsURLConnection) new URL("https://api.idex.market/returnTicker").openConnection();
 c.setRequestMethod("POST");
 c.setRequestProperty("Accept-Encoding", "gzip");
 c.setRequestProperty("User-Agent", "irrelevant");
 ObjectMapper objectMapper = new ObjectMapper();
 try (InputStream inputStream = c.getInputStream();
   GZIPInputStream in = new GZIPInputStream(inputStream);
   InputStreamReader inputStreamReader = new InputStreamReader(in)) {
  o =
    objectMapper
      .readerFor(ReturnTickerRequestedWithNull.class)
      .readValue(inputStreamReader);
 }
 return o;
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

URL console = new URL(urlNameString);
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
conn.setRequestProperty(ACCEPT, "*/*");
conn.setRequestProperty(CONNECTION, CONNECTION_VALUE);
conn.setRequestProperty(USER_AGENT, USER_AGENT_VALUE);
conn.setRequestProperty(ACCEPT_CHARSET, UTF8);
conn.setRequestProperty(CONTENTTYPE, UTF8);
conn.setDoOutput(true);
conn.setDoInput(true);

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

conn.setDoInput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("User-Agent", DEFAULT_USER_AGENT);
conn.connect();

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

con.setConnectTimeout(30 * 1000);
con.setReadTimeout(60 * 1000);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()), 1024*1024);
while (true) {

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

conn.setDoInput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("User-Agent", DEFAULT_USER_AGENT);
conn.connect();

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

conn.setDoOutput(true);
  conn.setRequestMethod("POST");
  conn.setRequestProperty("Content-Type", "application/json");
} catch (IOException e) {
  GlowServer.logger.log(Level.WARNING, "Failed to look up UUID", e);

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

con.setConnectTimeout(10 * 1000);
con.setReadTimeout(5 * 1000);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()), 1024*1024);
while (true) {

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

HttpsURLConnection connection = (HttpsURLConnection) downloadUrl
    .openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0");

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

con.setConnectTimeout(10 * 1000);
con.setReadTimeout(5 * 1000);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()), 1024*1024);
while (true) {

代码示例来源:origin: apache/nifi

@Override
  public void run() {
    try {
      final int port = ((HandleHttpRequest) runner.getProcessor()).getPort();
      final HttpsURLConnection connection = (HttpsURLConnection) new URL("https://localhost:"
          + port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").openConnection();
      connection.setSSLSocketFactory(sslContext.getSocketFactory());
      connection.setDoOutput(false);
      connection.setRequestMethod("GET");
      connection.setRequestProperty("header1", "value1");
      connection.setRequestProperty("header2", "");
      connection.setRequestProperty("header3", "apple=orange");
      connection.setConnectTimeout(3000);
      connection.setReadTimeout(3000);
      StreamUtils.copy(connection.getInputStream(), new NullOutputStream());
    } catch (final Throwable t) {
      t.printStackTrace();
      Assert.fail(t.toString());
    }
  }
});

代码示例来源: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: ihaolin/antares

/**
 * 设置请求header
 * @param name 名称
 * @param value 值
 * @return this
 */
public Https header(final String name, final String value) {
  connection.setRequestProperty(name, value);
  return this;
}

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

/**
 * Sets the request header field to the given value.
 *
 * @param field The header field name.
 * @param value The header field value.
 */
public void setRequestHeader(String field, String value)
{
  // Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_010: [The function shall set the given request header field.]
  this.connection.setRequestProperty(field, value);
}

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

static HttpsURLConnection configureAdditionalHeaders(
    final HttpsURLConnection conn, final Map<String, String> headers)
    throws IOException {
  if (headers != null) {
    for (final Map.Entry<String, String> entry : headers.entrySet()) {
      conn.setRequestProperty(entry.getKey(), entry.getValue());
    }
  }
  return conn;
}

代码示例来源:origin: adjust/android_sdk

@Override
  public void applyConnectionOptions(HttpsURLConnection connection, String clientSdk) {
    connection.setRequestProperty("Client-SDK", clientSdk);
    connection.setConnectTimeout(Constants.ONE_MINUTE);
    connection.setReadTimeout(Constants.ONE_MINUTE);
    if (userAgent != null) {
      connection.setRequestProperty("User-Agent", userAgent);
    }
  }
}

代码示例来源:origin: facebook/facebook-java-business-sdk

public ResponseWrapper sendDelete(String apiUrl, Map<String, Object> allParams, APIContext context) throws APIException, IOException {
 URL url = new URL(RequestHelper.constructUrlString(apiUrl, allParams));
 context.log("Delete: " + url.toString());
 HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
 con.setRequestMethod("DELETE");
 con.setRequestProperty("User-Agent", USER_AGENT);
 return readResponse(con);
}

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

private static void prepareConnection(HttpsURLConnection connection,
    int length) throws ProtocolException {
  connection.setRequestMethod("POST");
  connection.setDoInput(true);
  connection.setDoOutput(true);
  connection.setUseCaches(false);
  connection.setRequestProperty(HTTP_FIELD_CONTENT_TYPE, CONTENT_TYPE_URLENCODED);
  connection.setRequestProperty(HTTP_FIELD_CONTENT_LENGTH, String.valueOf(length));
}

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

protected static HttpsURLConnection getHttpsConnection(long length, URI uri) throws IOException {
    HttpsURLConnection conn = (HttpsURLConnection) uri.toURL().openConnection();
    conn.setDoOutput(true);
    conn.setRequestMethod("PUT");
    conn.setRequestProperty("Content-Length", String.valueOf(length));
    conn.setRequestProperty("Date", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX").withZone(ZoneOffset.UTC).format(Instant.now()));
    conn.setRequestProperty("Host", uri.getHost());

    return conn;
  }
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private Map<Address, Address> callService() throws IOException, CertificateException {
  URL url = new URL(endpointUrl);
  HttpsURLConnection httpsConnection = (HttpsURLConnection) url.openConnection();
  httpsConnection.setRequestMethod("GET");
  httpsConnection.setConnectTimeout(connectionTimeoutInMillis);
  httpsConnection.setReadTimeout(connectionTimeoutInMillis);
  httpsConnection.setRequestProperty("Accept-Charset", "UTF-8");
  httpsConnection.connect();
  checkCertificate(httpsConnection);
  checkError(httpsConnection);
  return parseResponse(httpsConnection.getInputStream());
}

相关文章

HttpsURLConnection类方法