Android Native
Enabling URLConnection for tunneling
The MicroVPNSDK.createURLConnection(…)
method is used to configure a URL object for tunneling through the MVPN tunnel. This method returns the modified URLConnection object that is enabled for tunneling. Since #startTunnel(…)
is an asynchronous call, the tunnel needs to be started before calling this API. Otherwise it throws a NetworkTunnelNotStartedException exception.
StringBuilder response = new StringBuilder();
try {
URL url = new URL(strUrl[0]);
URLConnection urlConnection = MicroVPNSDK.createURLConnection(context, url);
HttpURLConnection conn = (HttpURLConnection) urlConnection;
int responseCode = conn.getResponseCode();
InputStream inputStream;
if (200 <= responseCode && responseCode <= 299) {
inputStream = conn.getInputStream();
} else {
inputStream = conn.getErrorStream();
}
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
String currentLine;
while ((currentLine = in.readLine()) != null) {
response.append(currentLine);
}
in.close();
} catch (NetworkTunnelNotStartedException e) {
Log.e(LOG_TAG, e.getMessage());
} catch(Exception e) {
Log.e(LOG_TAG, e.getMessage());
}
<!--NeedCopy-->
Enabling URLConnection for tunneling
In this article
Copied!
Failed!