I have a method that I use to get the auth token for a user. I have
been using it for months with no problem. All of the sudden today it
stated failing with:
IOException java.net.UnknownHostException: Host is unresolved:
www.google.com:443
The manifest contains <uses-permission
android:name="android.permission.INTERNET" />
The code has not changed since it worked. It is:
public static String getAuthToken( String gmail, String pwd )
{
//=================================== Validate params
if( gmail == null || gmail.length() == 0 )
return null;
if( pwd == null || pwd.length() == 0 )
return null;
if( gmail.toLowerCase().endsWith( "@gmail.com" ) == false )
gmail += "@gmail.com";
//=================================== Get the auth token
String authToken = null;
try
{
HttpsURLConnection uc = (HttpsURLConnection)new
URL( mAuthURL ).openConnection();
if( uc != null )
{
HostnameVerifier HOSTNAME_VERIFIER = new
HostnameVerifier()
{
public boolean verify( String hostname,
SSLSession session )
{
return mHostName.equals(
hostname );
}
};
uc.setHostnameVerifier( HOSTNAME_VERIFIER );
uc.setDoOutput( true );
uc.setRequestMethod( "POST" );
uc.setRequestProperty( "Content-Type",
"application/x-www-form-
urlencoded" );
uc.setUseCaches( false );
BufferedWriter bw = new BufferedWriter( new
OutputStreamWriter( uc.getOutputStream() ), BUFFER_SIZE );
if( bw != null )
{
bw.write( URLEncoder.encode(
"accountType", "UTF-8" ) + "=" +
URLEncoder.encode( "HOSTED_OR_GOOGLE", "UTF-8" ) + "&" );
bw.write( URLEncoder.encode( "Email",
"UTF-8" ) + "=" +
URLEncoder.encode( gmail, "UTF-8" ) + "&" );
bw.write( URLEncoder.encode( "Passwd",
"UTF-8" ) + "=" +
URLEncoder.encode( pwd, "UTF-8" ) + "&" );
bw.write( URLEncoder.encode( "source",
"UTF-8" ) + "=" +
URLEncoder.encode( "icd-MyCalendar", "UTF-8" ) + "&" );
bw.write( URLEncoder.encode( "service",
"UTF-8" ) + "=" +
URLEncoder.encode( "cl", "UTF-8" ) );
bw.close();
}
if( uc.getResponseCode() !=
HttpsURLConnection.HTTP_FORBIDDEN )
{
BufferedReader in = new BufferedReader(
new
InputStreamReader( uc.getInputStream() ), BUFFER_SIZE );
if( in != null )
{
for( String line =
in.readLine(); line != null; line =
in.readLine() )
if( line != null &&
line.toLowerCase().startsWith( "auth=" ) )
{
authToken =
line.substring( 5 );
break;
}
in.close();
}
}
}
}
catch( IOException ex )
{
ex.printStackTrace();
}
return authToken;
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en