プログラムでAndroidのユーザー名とパスワードを持つVPNサーバーに接続したい。
これを達成するのを手伝ってください。
ありがとう
これを試してみてください
public String getUrlContent(String urlstring,final String user,final String password) throws IOException
{
byte[] rawbyte = null;
URL url = new URL(urlstring);
Authenticator.setDefault(new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}});
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.setUseCaches(false);
urlConnection.connect();
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK)
{
try
{
InputStream in = new BufferedInputStream(
urlConnection.getInputStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
int c;
while ((c = in.read()) != -1)
{
out.write(c);
}
out.flush();
rawbyte = out.toByteArray();
urlConnection.disconnect();
in.close();
out.close();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return new String(rawbyte);
}
return null;
}