listing13-09_htmltool.java_usingpreprocessingextension

来自「着几乎所有智能机厂商都将有自己配套的App Store,甚至并非智能手机制造商的」· JAVA_USINGPREPROCESSINGEXTENSION 代码 · 共 25 行

JAVA_USINGPREPROCESSINGEXTENSION
25
字号
public byte[] openHttpConnection( String url )
throws IOException, SecurityException
{
	HttpConnection connection = (HttpConnection)
	Connector.open( url,Connector.READ_WRITE, true );
	connection.setRequestMethod( HttpConnection.GET );
	connection.setRequestProperty("Connection", "close");

	//#useragent connection.setRequestProperty( "UserAgent", "${useragent}" );

	int responseCode = connection.getResponseCode();
	if ( responseCode == HttpConnection.HTTP_OK ) {
		InputStream in = connection.openInputStream();
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		byte[] buffer = new byte[ 5 * 1024 ];
		int read;
		while ( ( read = in.read( buffer, 0, buffer.length ) ) != -1 ) {
			out.write( buffer, 0, read );
		}
		return out.toByteArray();
	} else {
		throw new IOException( "Got invalid response code: " + responseCode );
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?