當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpsURLConnection.getResponseMessage方法代碼示例

本文整理匯總了Java中javax.net.ssl.HttpsURLConnection.getResponseMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpsURLConnection.getResponseMessage方法的具體用法?Java HttpsURLConnection.getResponseMessage怎麽用?Java HttpsURLConnection.getResponseMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.HttpsURLConnection的用法示例。


在下文中一共展示了HttpsURLConnection.getResponseMessage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createTopicsIfNecessary

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
public void createTopicsIfNecessary( String... topics ) throws Exception{
	SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
	sslContext.init(null, null, null);
	for( String topic : topics ){
		URL messageHubUrl = new URL( getConfig(MessageHubConfig.MESSAGEHUB_REST_URL) + "/admin/topics" );
		HttpsURLConnection con = (HttpsURLConnection) messageHubUrl.openConnection();
		con.setDoOutput(true);
		con.setDoInput(true);
		con.setRequestProperty("Content-Type", "application/json");
		con.setRequestProperty("X-Auth-Token", getConfig(MessageHubConfig.MESSAGEHUB_API_KEY));
		con.setRequestProperty("Accept", "application/json");
		con.setRequestMethod("POST");

		OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
		wr.write( "{\"name\":\"" + topic + "\"}" );
		wr.flush();

		int res = con.getResponseCode();
		switch (res){
		case 200:
		case 202:
			System.out.println("Successfully created topic: " + topic);
			break;            	   
		case 422:
		case 403: 
			System.out.println("Topic already exists in the server: " + topic);
			break;
		default:
			throw new IllegalStateException("Error when trying to create topic: " + res + " Reason: " + con.getResponseMessage());
		}
	}
}
 
開發者ID:ibm-watson-data-lab,項目名稱:advo-beta-producer,代碼行數:33,代碼來源:MessageHubConfig.java

示例2: uploadAttachment

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
private byte[] uploadAttachment(String method, String url, InputStream data,
                                long dataSize, byte[] key, ProgressListener listener)
  throws IOException
{
  URL                uploadUrl  = new URL(url);
  HttpsURLConnection connection = (HttpsURLConnection) uploadUrl.openConnection();
  connection.setDoOutput(true);

  if (dataSize > 0) {
    connection.setFixedLengthStreamingMode((int) AttachmentCipherOutputStream.getCiphertextLength(dataSize));
  } else {
    connection.setChunkedStreamingMode(0);
  }

  connection.setRequestMethod(method);
  connection.setRequestProperty("Content-Type", "application/octet-stream");
  connection.setRequestProperty("Connection", "close");
  connection.connect();

  try {
    OutputStream                 stream = connection.getOutputStream();
    AttachmentCipherOutputStream out    = new AttachmentCipherOutputStream(key, stream);
    byte[]                       buffer = new byte[4096];
    int                   read, written = 0;

    while ((read = data.read(buffer)) != -1) {
      out.write(buffer, 0, read);
      written += read;

      if (listener != null) {
        listener.onAttachmentProgress(dataSize, written);
      }
    }

    data.close();
    out.flush();
    out.close();

    if (connection.getResponseCode() != 200) {
      throw new IOException("Bad response: " + connection.getResponseCode() + " " + connection.getResponseMessage());
    }

    return out.getAttachmentDigest();
  } finally {
    connection.disconnect();
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-lib,代碼行數:48,代碼來源:PushServiceSocket.java


注:本文中的javax.net.ssl.HttpsURLConnection.getResponseMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。