本文整理汇总了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());
}
}
}
示例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();
}
}