Created
January 3, 2014 01:51
-
-
Save jhelmig/8231152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected String doInBackground(String... params) { | |
| String urlString=params[0]; | |
| String resultToDisplay; | |
| emailVerificationResult result = null; | |
| InputStream in = null; | |
| // HTTP Get | |
| try { | |
| URL url = new URL(urlString); | |
| HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); | |
| in = new BufferedInputStream(urlConnection.getInputStream()); | |
| } catch (Exception e ) { | |
| System.out.println(e.getMessage()); | |
| return e.getMessage(); | |
| } | |
| // Parse XML | |
| XmlPullParserFactory pullParserFactory; | |
| try { | |
| pullParserFactory = XmlPullParserFactory.newInstance(); | |
| XmlPullParser parser = pullParserFactory.newPullParser(); | |
| parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); | |
| parser.setInput(in, null); | |
| result = parseXML(parser); | |
| } catch (XmlPullParserException e) { | |
| e.printStackTrace(); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| // Simple logic to determine if the email is dangerous, invalid, or valid | |
| if (result != null ) { | |
| if( result.hygieneResult.equals("Spam Trap")) { | |
| resultToDisplay = "Dangerous email, please correct"; | |
| } | |
| else if( Integer.parseInt(result.statusNbr) >= 300) { | |
| resultToDisplay = "Invalid email, please re-enter"; | |
| } | |
| else { | |
| resultToDisplay = "Thank you for your submission"; | |
| } | |
| } | |
| else { | |
| resultToDisplay = "Exception Occured"; | |
| } | |
| return resultToDisplay; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment