本文整理了Java中javax.net.ssl.HttpsURLConnection.getRequestMethod()
方法的一些代码示例,展示了HttpsURLConnection.getRequestMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpsURLConnection.getRequestMethod()
方法的具体详情如下:
包路径:javax.net.ssl.HttpsURLConnection
类名称:HttpsURLConnection
方法名:getRequestMethod
暂无
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testApplyHeaders() throws ProtocolException, MalformedURLException,
URISyntaxException {
final Map<String, String> headers = new HashMap<String, String>();
headers.put("testKey", "testValue");
headers.put(HttpHeader.CONTENT_LENGTH, "I should not be added");
headers.put(HttpHeader.HOST, "I should not be added");
final HttpRequest request = new HttpRequest("POST", new URI("https://www.test.com"), headers,
null);
final HttpsURLConnection conn = (HttpsURLConnection) client.applyHeadersAndMethod(request,
new MockHttpURLConnection(new URL("https://www.test.com")));
assertEquals(conn.getRequestProperty("testKey"), "testValue");
assertNull(conn.getRequestProperty(HttpHeader.CONTENT_LENGTH));
assertNull(conn.getRequestProperty(HttpHeader.HOST));
assertEquals(conn.getRequestMethod(), "POST");
}
代码示例来源:origin: org.talend.components/components-marketo-runtime
protected InputStreamReader getReaderFromHttpResponse(HttpsURLConnection conn)
throws MarketoException, IOException {
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
InputStream inStream = conn.getInputStream();
return new InputStreamReader(inStream);
} else {
LOG.error("{} request failed: {}.", conn.getRequestMethod(), responseCode);
throw new MarketoException(REST, responseCode, "Request failed! Please check your request setting!");
}
}
代码示例来源:origin: Talend/components
protected InputStreamReader getReaderFromHttpResponse(HttpsURLConnection conn)
throws MarketoException, IOException {
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
InputStream inStream = conn.getInputStream();
return new InputStreamReader(inStream);
} else {
LOG.error("{} request failed: {}.", conn.getRequestMethod(), responseCode);
throw new MarketoException(REST, responseCode, "Request failed! Please check your request setting!");
}
}
代码示例来源:origin: com.microsoft.azure.iothub-java-client/iothub-java-device-client
/**
* Saves the body to be sent with the request.
*
* @param body the request body.
*
* @throws IllegalArgumentException if the request does not currently use
* method POST or PUT and the body is non-empty. This is because Java's
* {@link HttpsURLConnection} silently converts the HTTPS method to POST or PUT if a
* body is written to the request.
*/
public void writeOutput(byte[] body)
{
// Codes_SRS_HTTPSCONNECTION_11_010: [The function shall throw an IllegalArgumentException if the request does not currently use method POST or PUT and the body is non-empty.]
HttpsMethod method = HttpsMethod.valueOf(
this.connection.getRequestMethod());
if (method != HttpsMethod.POST && method != HttpsMethod.PUT)
{
if (body.length > 0)
{
throw new IllegalArgumentException(
"Cannot write a body to a request that "
+ "is not a POST or a PUT request.");
}
}
else
{
// Codes_SRS_HTTPSCONNECTION_11_009: [The function shall save the body to be sent with the request.]
this.body = Arrays.copyOf(body, body.length);
}
}
代码示例来源:origin: Azure/azure-iot-sdk-java
/**
* Saves the body to be sent with the request.
*
* @param body The request body.
*
* @throws IllegalArgumentException if the request does not currently use
* method POST or PUT and the body is non-empty. This is because Java's
* HttpsURLConnection silently converts the HTTPS method to POST or PUT if a
* body is written to the request.
*/
public void writeOutput(byte[] body)
{
// Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_013: [The function shall throw an IllegalArgumentException if the request does not currently use method POST or PUT and the body is non-empty.]
HttpMethod method = HttpMethod.valueOf(
this.connection.getRequestMethod());
if (method != HttpMethod.POST && method != HttpMethod.PUT)
{
if (body.length > 0)
{
throw new IllegalArgumentException(
"Cannot write a body to a request that "
+ "is not a POST or a PUT request.");
}
}
else
{
// Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_012: [The function shall save the body to be sent with the request.]
this.body = Arrays.copyOf(body, body.length);
}
}
代码示例来源:origin: Azure/azure-iot-sdk-java
/**
* Saves the body to be sent with the request.
*
* @param body The request body.
*
* @throws IllegalArgumentException if the request does not currently use
* method POST or PUT and the body is non-empty. This is because Java's
* HttpsURLConnection silently converts the HTTPS method to POST or PUT if a
* body is written to the request.
*/
public void writeOutput(byte[] body)
{
// Codes_SRS_HTTPCONNECTION_25_013: [The function shall throw an IllegalArgumentException if the request does not currently use method POST or PUT and the body is non-empty.]
HttpMethod method = HttpMethod.valueOf(
this.connection.getRequestMethod());
if (method != HttpMethod.POST && method != HttpMethod.PUT)
{
if (body.length > 0)
{
throw new IllegalArgumentException(
"Cannot write a body to a request that "
+ "is not a POST or a PUT request.");
}
}
else
{
// Codes_SRS_HTTPCONNECTION_25_012: [The function shall save the body to be sent with the request.]
this.body = Arrays.copyOf(body, body.length);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai
String method = conn.getRequestMethod();
内容来源于网络,如有侵权,请联系作者删除!