本文整理了Java中java.net.HttpURLConnection.getResponseMessage()
方法的一些代码示例,展示了HttpURLConnection.getResponseMessage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpURLConnection.getResponseMessage()
方法的具体详情如下:
包路径:java.net.HttpURLConnection
类名称:HttpURLConnection
方法名:getResponseMessage
[英]Returns the response message returned by the remote HTTP server.
[中]返回远程HTTP服务器返回的响应消息。
代码示例来源:origin: spring-projects/spring-framework
/**
* Validate the given response as contained in the {@link HttpURLConnection} object,
* throwing an exception if it does not correspond to a successful HTTP response.
* <p>Default implementation rejects any HTTP status code beyond 2xx, to avoid
* parsing the response body and trying to deserialize from a corrupted stream.
* @param config the HTTP invoker configuration that specifies the target service
* @param con the HttpURLConnection to validate
* @throws IOException if validation failed
* @see java.net.HttpURLConnection#getResponseCode()
*/
protected void validateResponse(HttpInvokerClientConfiguration config, HttpURLConnection con)
throws IOException {
if (con.getResponseCode() >= 300) {
throw new IOException(
"Did not receive successful HTTP response: status code = " + con.getResponseCode() +
", status message = [" + con.getResponseMessage() + "]");
}
}
代码示例来源:origin: stackoverflow.com
HttpURLConnection connection = null;
try {
URL url = new URL(sUrl[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
return "Server returned HTTP " + connection.getResponseCode()
+ " " + connection.getResponseMessage();
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private InputStream readData(int offset, int length) throws IOException{
HttpURLConnection conn = (HttpURLConnection) zipUrl.openConnection();
conn.setDoOutput(false);
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(false);
String range = "-";
if (offset != Integer.MAX_VALUE){
range = offset + range;
}
if (length != Integer.MAX_VALUE){
if (offset != Integer.MAX_VALUE){
range = range + (offset + length - 1);
}else{
range = range + length;
}
}
conn.setRequestProperty("Range", "bytes=" + range);
conn.connect();
if (conn.getResponseCode() == HttpURLConnection.HTTP_PARTIAL){
return conn.getInputStream();
}else if (conn.getResponseCode() == HttpURLConnection.HTTP_OK){
throw new IOException("Your server does not support HTTP feature Content-Range. Please contact your server administrator.");
}else{
throw new IOException(conn.getResponseCode() + " " + conn.getResponseMessage());
}
}
代码示例来源:origin: bumptech/glide
return null;
final int statusCode = urlConnection.getResponseCode();
if (isHttpOk(statusCode)) {
return getStreamForSuccessfulRequest(urlConnection);
throw new HttpException("Received empty or null redirect url");
URL redirectUrl = new URL(url, redirectUrlString);
throw new HttpException(statusCode);
} else {
throw new HttpException(urlConnection.getResponseMessage(), statusCode);
代码示例来源:origin: geotools/geotools
gazetteerURL = new URL(gazetteer.toString() + "&placename=" + place);
} catch (MalformedURLException e) {
results.error(feature, e.toString());
(HttpURLConnection) gazetteerURL.openConnection();
if (!("OK".equals(gazetteerConnection.getResponseMessage()))) {
results.error(
feature, "An error occured creating the connection to the Gazetteer.");
代码示例来源:origin: stackoverflow.com
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(10000);
connection.setConnectTimeout(15000);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Cache-Control", "no-cache");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
dataOutputStream.close();
String responseMessage = connection.getResponseMessage();
Log.d(TAG, responseMessage);
代码示例来源:origin: google/agera
@NonNull
private HttpResponse getHttpResponseResult(final @NonNull HttpRequest request,
@NonNull final HttpURLConnection connection) throws IOException {
connection.setConnectTimeout(request.connectTimeoutMs);
connection.setReadTimeout(request.readTimeoutMs);
connection.setInstanceFollowRedirects(request.followRedirects);
connection.setUseCaches(request.useCaches);
connection.setDoInput(true);
connection.setRequestMethod(request.method);
for (final Entry<String, String> headerField : request.header.entrySet()) {
connection.addRequestProperty(headerField.getKey(), headerField.getValue());
}
final byte[] body = request.body;
if (body.length > 0) {
connection.setDoOutput(true);
final OutputStream out = connection.getOutputStream();
try {
out.write(body);
} finally {
out.close();
}
}
final String responseMessage = connection.getResponseMessage();
return httpResponse(connection.getResponseCode(),
responseMessage != null ? responseMessage : "",
getHeader(connection), getByteArray(connection));
}
代码示例来源:origin: stackoverflow.com
String addr = "http://172.26.41.18:8080/domain/list";
URL url = new URL(addr);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setUseCaches(false);
httpCon.setAllowUserInteraction(false);
httpCon.addRequestProperty("Authorization", "Basic YWRtaW4fYFgjkl5463");
System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage());
代码示例来源:origin: jenkinsci/jenkins
String auth = new URL(home).getUserInfo();
if(auth != null) auth = "Basic " + new Base64Encoder().encode(auth.getBytes("UTF-8"));
HttpURLConnection con = open(new URL(home));
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if(con.getResponseCode()!=200
|| con.getHeaderField("X-Hudson")==null) {
System.err.println(home+" is not Hudson ("+con.getResponseMessage()+")");
return -1;
URL jobURL = new URL(home + "job/" + Util.encode(projectName).replace("/", "/job/") + "/");
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if(con.getResponseCode()!=200) {
System.err.println(jobURL + " is not a valid external job (" + con.getResponseCode() + " " + con.getResponseMessage() + ")");
return -1;
代码示例来源:origin: osmandapp/Osmand
conn.setDoInput(true);
conn.setDoOutput(false);
conn.setRequestMethod("GET");
if(userNamePassword != null) {
conn.setRequestProperty("Authorization", "Basic " + Base64.encode(userNamePassword)); //$NON-NLS-1$ //$NON-NLS-2$
log.info("Response code and message : " + conn.getResponseCode() + " " + conn.getResponseMessage());
if(conn.getResponseCode() != 200){
return conn.getResponseMessage();
代码示例来源:origin: facebook/stetho
public URLConnectionInspectorResponse(String requestId, HttpURLConnection conn) throws IOException {
super(Util.convertHeaders(conn.getHeaderFields()));
mRequestId = requestId;
mUrl = conn.getURL().toString();
mStatusCode = conn.getResponseCode();
mStatusMessage = conn.getResponseMessage();
}
代码示例来源:origin: aws-amplify/aws-sdk-android
/**
* Fetches a file from the URI given and returns an input stream to it.
*
* @param uri the uri of the file to fetch
* @param config optional configuration overrides
* @return an InputStream containing the retrieved data
* @throws IOException on error
*/
public static InputStream fetchFile(
final URI uri,
final ClientConfiguration config) throws IOException {
final URL url = uri.toURL();
// TODO: support proxy?
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(getConnectionTimeout(config));
connection.setReadTimeout(getSocketTimeout(config));
connection.addRequestProperty("User-Agent", getUserAgent(config));
if (connection.getResponseCode() != HTTP_STATUS_OK) {
final InputStream is = connection.getErrorStream();
if (is != null) {
is.close();
}
connection.disconnect();
throw new IOException("Error fetching file from " + uri + ": "
+ connection.getResponseMessage());
}
return connection.getInputStream();
}
代码示例来源:origin: stackoverflow.com
URL url = new URL("http://www.google.com");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
String responseMsg = con.getResponseMessage();
int response = con.getResponseCode();
return null;
代码示例来源:origin: jeremylong/DependencyCheck
final URL url = new URL(String.format(query, rootURL, sha1));
conn.connect();
if (conn.getResponseCode() == 200) {
boolean missing = false;
try {
final String errorMessage = "Could not connect to MavenCentral (" + conn.getResponseCode() + "): " + conn.getResponseMessage();
throw new IOException(errorMessage);
代码示例来源:origin: jeremylong/DependencyCheck
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("user-agent", "npm/6.1.0 node/v10.5.0 linux x64");
conn.setRequestProperty("npm-in-ci", "false");
switch (conn.getResponseCode()) {
case 200:
try (InputStream in = new BufferedInputStream(conn.getInputStream());
conn.getResponseCode(), conn.getResponseMessage());
throw new SearchException("Could not perform Node Audit analysis. Invalid payload submitted to Node Audit API.");
default:
LOGGER.debug("Could not connect to Node Audit API. Received response code: {} {}",
conn.getResponseCode(), conn.getResponseMessage());
throw new IOException("Could not connect to Node Audit API");
代码示例来源:origin: org.springframework/spring-web
/**
* Validate the given response as contained in the {@link HttpURLConnection} object,
* throwing an exception if it does not correspond to a successful HTTP response.
* <p>Default implementation rejects any HTTP status code beyond 2xx, to avoid
* parsing the response body and trying to deserialize from a corrupted stream.
* @param config the HTTP invoker configuration that specifies the target service
* @param con the HttpURLConnection to validate
* @throws IOException if validation failed
* @see java.net.HttpURLConnection#getResponseCode()
*/
protected void validateResponse(HttpInvokerClientConfiguration config, HttpURLConnection con)
throws IOException {
if (con.getResponseCode() >= 300) {
throw new IOException(
"Did not receive successful HTTP response: status code = " + con.getResponseCode() +
", status message = [" + con.getResponseMessage() + "]");
}
}
代码示例来源:origin: apache/activemq
public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException {
URL url = createMessageURL(message);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("DELETE");
try {
connection.connect();
} catch (IOException e) {
throw new IOException("DELETE failed on: " + url, e);
} finally {
connection.disconnect();
}
if (!isSuccessfulCode(connection.getResponseCode())) {
throw new IOException("DELETE was not successful: " + connection.getResponseCode() + " "
+ connection.getResponseMessage());
}
}
代码示例来源:origin: jeremylong/DependencyCheck
final URL url = new URL(rootURL, String.format("identify/sha1/%s",
sha1.toLowerCase()));
conn.connect();
switch (conn.getResponseCode()) {
case 200:
try {
default:
LOGGER.debug("Could not connect to Nexus received response code: {} {}",
conn.getResponseCode(), conn.getResponseMessage());
throw new IOException("Could not connect to Nexus");
代码示例来源:origin: spring-projects/spring-security-oauth
connection.setRequestMethod(httpMethod);
out.close();
responseCode = connection.getResponseCode();
responseMessage = connection.getResponseMessage();
if (responseMessage == null) {
responseMessage = "Unknown Error";
代码示例来源:origin: wildfly/wildfly
/**
* Check if the specified bucket exists (via a HEAD request)
* @param bucket The name of the bucket to check
* @return true if HEAD access returned success
*/
public boolean checkBucketExists(String bucket) throws IOException {
HttpURLConnection response=makeRequest("HEAD", bucket, "", null, null);
int httpCode=response.getResponseCode();
if(httpCode >= 200 && httpCode < 300)
return true;
if(httpCode == HttpURLConnection.HTTP_NOT_FOUND) // bucket doesn't exist
return false;
throw new IOException("bucket '" + bucket + "' could not be accessed (rsp=" +
httpCode + " (" + response.getResponseMessage() + "). Maybe the bucket is owned by somebody else or " +
"the authentication failed");
}
内容来源于网络,如有侵权,请联系作者删除!