本文整理匯總了Java中java.net.HttpURLConnection.getClass方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpURLConnection.getClass方法的具體用法?Java HttpURLConnection.getClass怎麽用?Java HttpURLConnection.getClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.HttpURLConnection
的用法示例。
在下文中一共展示了HttpURLConnection.getClass方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSetFixedLengthStreamingModeLong
import java.net.HttpURLConnection; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
@OnlyRunCronetHttpURLConnection
public void testSetFixedLengthStreamingModeLong() throws Exception {
URL url = new URL(NativeTestServer.getEchoBodyURL());
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
String dataString = "some very important data";
byte[] data = dataString.getBytes();
Class<?> c = connection.getClass();
Method method = c.getMethod("setFixedLengthStreamingMode",
new Class[] {long.class});
method.invoke(connection, (long) data.length);
OutputStream out = connection.getOutputStream();
out.write(data);
assertEquals(200, connection.getResponseCode());
assertEquals("OK", connection.getResponseMessage());
assertEquals(dataString, TestUtil.getResponseAsString(connection));
connection.disconnect();
}
}