2

我想以编程方式连接到在 android 中具有用户名和密码的 VPN 服务器。

请帮助我实现这一目标。

谢谢

4

2 回答 2

1

试试这个可能对你有帮助

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;
    }
于 2013-09-05T11:12:06.793 回答
0

你可以试试xinkvpn,这里是github链接:https ://github.com/xinthink/xinkvpn

于 2013-09-05T11:41:20.393 回答