JAVA Example

From CDYNE Wiki
Jump to navigation Jump to search

Check Phone Number

 1 import java.io.ByteArrayOutputStream;
 2 import java.io.InputStream;
 3 import java.net.MalformedURLException;
 4 import java.net.URL; 
 5 import java.util.Properties;
 6 import javax.xml.transform.OutputKeys;
 7 import javax.xml.transform.Source;
 8 import javax.xml.transform.Transformer;
 9 import javax.xml.transform.TransformerFactory;
10 import javax.xml.transform.stream.StreamResult;
11 import javax.xml.transform.stream.StreamSource;
12 
13 public class CheckPhoneNumber {
14 
15     public static void main(String[] args) {
16           try{		
17             URL url = new URL("http://ws.cdyne.com/phoneverify/phoneverify.asmx/CheckPhoneNumber?"
18                                + "PhoneNumber=17575449510"
19                                + "&LicenseKey=YOUR LICENSE KEY");		
20     try{			
21     InputStream in = url.openStream(); 
22     StreamSource source = new StreamSource(in); 			
23     printResult(source);	
24 }catch(java.io.IOException e){			
25     e.printStackTrace();		
26 }		
27 }catch (MalformedURLException e){		
28     e.printStackTrace();	
29             }     
30     }     
31     private static void printResult(Source source) {        
32             try {            
33             ByteArrayOutputStream bos = new ByteArrayOutputStream();
34             StreamResult sr = new StreamResult(bos);
35             Transformer trans = TransformerFactory.newInstance().newTransformer();
36             Properties oprops = new Properties();
37             oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
38             trans.setOutputProperties(oprops);
39             trans.transform(source, sr);            
40             System.out.println("**** Response ******");            
41             System.out.println(bos.toString());   
42 
43             bos.close();
44             System.out.println();        
45     } catch (Exception e) {            
46             }    
47     }
48 }

Check Phone Numbers

 1 import java.io.ByteArrayOutputStream;
 2 import java.io.InputStream;
 3 import java.net.MalformedURLException;
 4 import java.net.URL; 
 5 import java.util.Properties;
 6 import javax.xml.transform.OutputKeys;
 7 import javax.xml.transform.Source;
 8 import javax.xml.transform.Transformer;
 9 import javax.xml.transform.TransformerFactory;
10 import javax.xml.transform.stream.StreamResult;
11 import javax.xml.transform.stream.StreamSource;
12 
13 public class CheckPhoneNumbers {
14 
15     public static void main(String[] args) {
16           try{		
17             URL url = new URL("http://ws.cdyne.com/phoneverify/phoneverify.asmx/CheckPhoneNumbers?"
18                                + "PhoneNumbers=17575449510"
19                                + "&PhoneNumbers=18009843710"
20                                + "&LicenseKey=YOUR LICENSE KEY");		
21     try{			
22     InputStream in = url.openStream(); 
23     StreamSource source = new StreamSource(in); 			
24     printResult(source);	
25 }catch(java.io.IOException e){			
26     e.printStackTrace();		
27 }		
28 }catch (MalformedURLException e){		
29     e.printStackTrace();	
30             }     
31     }     
32     private static void printResult(Source source) {        
33             try {            
34             ByteArrayOutputStream bos = new ByteArrayOutputStream();
35             StreamResult sr = new StreamResult(bos);
36             Transformer trans = TransformerFactory.newInstance().newTransformer();
37             Properties oprops = new Properties();
38             oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
39             trans.setOutputProperties(oprops);
40             trans.transform(source, sr);            
41             System.out.println("**** Response ******");            
42             System.out.println(bos.toString());   
43 
44             bos.close();
45             System.out.println();        
46     } catch (Exception e) {            
47             }    
48     }
49 }