本文整理了Java中java.net.HttpURLConnection.getRequestProperty()
方法的一些代码示例,展示了HttpURLConnection.getRequestProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpURLConnection.getRequestProperty()
方法的具体详情如下:
包路径:java.net.HttpURLConnection
类名称:HttpURLConnection
方法名:getRequestProperty
暂无
代码示例来源:origin: square/okhttp
@Override public String getRequestProperty(String field) {
return delegate.getRequestProperty(field);
}
代码示例来源:origin: prestodb/presto
@Override public String getRequestProperty(String field) {
return delegate.getRequestProperty(field);
}
代码示例来源:origin: aa112901/remusic
private int getRangeStart(HttpURLConnection request) {
String value = request.getRequestProperty(Constants.RANGE);
// Header rangeHeader = request.getFirstHeader(Constants.RANGE);
if (value != null) {
return Integer.valueOf(value.substring(value.indexOf("bytes=") + 6, value.indexOf("-")));
}
return 0;
}
代码示例来源:origin: TeamNewPipe/NewPipe
/**
* Open connection
*
* @param threadId id of the calling thread, used only for debug
* @param rangeStart range start
* @param rangeEnd range end
* @return a {@link java.net.URLConnection URLConnection} linking to the URL.
* @throws IOException if an I/O exception occurs.
*/
HttpURLConnection openConnection(int threadId, long rangeStart, long rangeEnd) throws IOException {
URL url = new URL(urls[current]);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setInstanceFollowRedirects(true);
if (rangeStart >= 0) {
String req = "bytes=" + rangeStart + "-";
if (rangeEnd > 0) req += rangeEnd;
conn.setRequestProperty("Range", req);
if (DEBUG) {
Log.d(TAG, threadId + ":" + conn.getRequestProperty("Range"));
}
}
return conn;
}
代码示例来源:origin: wildfly/wildfly
/**
* Add the appropriate Authorization header to the HttpURLConnection.
* @param connection The HttpURLConnection to which the header will be added.
* @param method The HTTP method to use (GET, PUT, DELETE)
* @param bucket the bucket name this request is for
* @param key the key this request is for
* @param pathArgs path arguments which are part of this request
*/
private void addAuthHeader(HttpURLConnection connection, String method, String bucket, String key, Map pathArgs) {
if(connection.getRequestProperty("Date") == null) {
connection.setRequestProperty("Date", httpDate());
}
if(connection.getRequestProperty("Content-Type") == null) {
connection.setRequestProperty("Content-Type", "");
}
if(this.awsAccessKeyId != null && this.awsSecretAccessKey != null) {
String canonicalString=
Utils.makeCanonicalString(method, bucket, key, pathArgs, connection.getRequestProperties());
String encodedCanonical=Utils.encode(this.awsSecretAccessKey, canonicalString, false);
connection.setRequestProperty("Authorization",
"AWS " + this.awsAccessKeyId + ":" + encodedCanonical);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
new DelegationTokenAuthenticatedURL.Token();
if (authRetryCount > 0) {
String contentType = conn.getRequestProperty(CONTENT_TYPE);
String requestMethod = conn.getRequestMethod();
URL url = conn.getURL();
代码示例来源:origin: spring-projects/spring-security
@Test
public void testNormalOperation() throws Exception {
// Setup client-side context
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken(
"Aladdin", "open sesame");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
// Create a connection and ensure our executor sets its
// properties correctly
AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor();
HttpURLConnection conn = new MockHttpURLConnection(new URL("http://localhost/"));
executor.prepareConnection(conn, 10);
// Check connection properties
// See http://www.faqs.org/rfcs/rfc1945.html section 11.1 for example
// we are comparing against
assertThat(conn.getRequestProperty("Authorization")).isEqualTo(
"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void testNullContextHolderIsNull() throws Exception {
SecurityContextHolder.getContext().setAuthentication(null);
// Create a connection and ensure our executor sets its
// properties correctly
AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor();
HttpURLConnection conn = new MockHttpURLConnection(new URL("http://localhost/"));
executor.prepareConnection(conn, 10);
// Check connection properties (shouldn't be an Authorization header)
assertThat(conn.getRequestProperty("Authorization")).isNull();
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void testNullContextHolderWhenAnonymous() throws Exception {
AnonymousAuthenticationToken anonymous = new AnonymousAuthenticationToken("key",
"principal", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
SecurityContextHolder.getContext().setAuthentication(anonymous);
// Create a connection and ensure our executor sets its
// properties correctly
AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor();
HttpURLConnection conn = new MockHttpURLConnection(new URL("http://localhost/"));
executor.prepareConnection(conn, 10);
// Check connection properties (shouldn't be an Authorization header)
assertThat(conn.getRequestProperty("Authorization")).isNull();
}
代码示例来源:origin: facebook/facebook-android-sdk
logger.appendKeyValue("URL", url);
logger.appendKeyValue("Method", connection.getRequestMethod());
logger.appendKeyValue("User-Agent", connection.getRequestProperty("User-Agent"));
logger.appendKeyValue("Content-Type", connection.getRequestProperty("Content-Type"));
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testSingleGetToHttpRequest() throws Exception {
GraphRequest requestMe = new GraphRequest(null, "TourEiffel");
HttpURLConnection connection = GraphRequest.toHttpConnection(requestMe);
assertTrue(connection != null);
assertEquals("GET", connection.getRequestMethod());
assertEquals("/" + FacebookSdk.getGraphApiVersion() + "/TourEiffel",
connection.getURL().getPath());
assertTrue(connection.getRequestProperty("User-Agent").startsWith("FBAndroidSDK"));
Uri uri = Uri.parse(connection.getURL().toString());
assertEquals("android", uri.getQueryParameter("sdk"));
assertEquals("json", uri.getQueryParameter("format"));
}
代码示例来源:origin: facebook/facebook-android-sdk
@LargeTest
public void testBuildsUploadPhotoHttpURLConnection() throws Exception {
Bitmap image = createTestBitmap(128);
GraphRequest request = GraphRequest.newUploadPhotoRequest(
AccessToken.getCurrentAccessToken(),
ShareInternalUtility.MY_PHOTOS,
image,
"Test photo messsage",
null,
null);
HttpURLConnection connection = GraphRequest.toHttpConnection(request);
assertTrue(connection != null);
assertNotSame("gzip", connection.getRequestProperty("Content-Encoding"));
assertNotSame("application/x-www-form-urlencoded", connection.getRequestProperty("Content-Type"));
}
代码示例来源:origin: mttkay/signpost
public String getContentType() {
return connection.getRequestProperty("Content-Type");
}
代码示例来源:origin: mttkay/signpost
public String getHeader(String name) {
return connection.getRequestProperty(name);
}
代码示例来源:origin: facebook/facebook-android-sdk
@SmallTest
public void testSetVersion() throws Exception {
String currentVersion = FacebookSdk.getGraphApiVersion();
FacebookSdk.setGraphApiVersion("v4.5");
GraphRequest requestMe = new GraphRequest(null, "TourEiffel");
HttpURLConnection connection = GraphRequest.toHttpConnection(requestMe);
assertTrue(connection != null);
assertEquals("GET", connection.getRequestMethod());
assertEquals("v4.5", FacebookSdk.getGraphApiVersion());
assertEquals("/v4.5" + "/TourEiffel", connection.getURL().getPath());
assertTrue(connection.getRequestProperty("User-Agent").startsWith("FBAndroidSDK"));
Uri uri = Uri.parse(connection.getURL().toString());
assertEquals("android", uri.getQueryParameter("sdk"));
assertEquals("json", uri.getQueryParameter("format"));
FacebookSdk.setGraphApiVersion(currentVersion);
}
}
代码示例来源:origin: dcm4che/dcm4che
private static void logOutgoing(HttpURLConnection connection) {
LOG.info("> " + connection.getRequestMethod() + " " + connection.getURL());
LOG.info("> Content-Type: " + connection.getRequestProperty("Content-Type"));
LOG.info("> Accept: " + connection.getRequestProperty("Accept"));
}
代码示例来源:origin: inspectIT/inspectIT
@Test
public void spanStartingContainsHeader() {
when(urlConnection.getRequestProperty(anyString())).thenReturn("bla bla");
ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(urlConnection, null, rsc);
assertThat(adapter.startClientSpan(), is(false));
}
代码示例来源:origin: inspectIT/inspectIT
@Test
public void spanStarting() {
when(urlConnection.getRequestProperty(anyString())).thenReturn(null);
ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(urlConnection, null, rsc);
assertThat(adapter.startClientSpan(), is(true));
}
代码示例来源:origin: Azure/azure-storage-android
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject();
assertNotNull(connection.getRequestProperty("x-ms-foo"));
assertNotNull(connection.getRequestProperty("x-ms-hello"));
}
};
代码示例来源:origin: braintree/braintree_android
@Test
public void sendsUserAgent() throws IOException, InvalidArgumentException {
String baseUrl = "http://example.com/graphql";
BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY);
HttpURLConnection connection = httpClient.init(baseUrl);
assertEquals("braintree/android/" + BuildConfig.VERSION_NAME, connection.getRequestProperty("User-Agent"));
}
内容来源于网络,如有侵权,请联系作者删除!