Sie sind auf Seite 1von 3

postData+="username="+username+"&password="+password+"&sender="+senderId+

"&message="+message+"&flash="+1+"&recipients="+recipients;

if (jComboBox30.getSelectedIndex()==3||jComboBox30.getSelectedIndex()==7)

jTextArea2.append(cE.getPhone());

else

1. import java.net.*;
2. import java.io.*;
3.
4. public class PostXml {
5. public static void main(String[] args) {
6. String[] recipients = {"2348023456789", "2348012345678"};
7. String xmlrecipients = "";
8. String username = "your_email_address";
9. String apikey = "your_apikey";
10. String sendername = "SenderName";
11. String message = "Enter your SMS message content here.";
12. String flash = "0";
13. String theoutput = "";
14. String randmsgid = Double.toString(Math.random());
15. for( int i =0; i < recipients.length; i++ ){
16. xmlrecipients += "<gsm><msidn>"+ recipients[i] + "</msidn><msgid>" + randmsgid +
"_" + i + "</msgid>" + "</gsm>";
17. }
18. String xmlrequest =
19. "<SMS>\n"
20. + "<auth>"
21. + "<username>" + username + "</username>\n"
22. + "<apikey>" + apikey + "</apikey>\n"
23. + "</auth>\n"
24. + "<message>"
25. + "<sender>" + sendername + "</sender>\n"
26. + "<messagetext>" + message + "</messagetext>\n"
27. + "<flash>" + flash + "</flash>\n"
28. + "</message>\n"
29. + "<recipients>\n"
30. + xmlrecipients
31. + "</recipients>\n"
32. + "</SMS>";
33.
34. String theurl = "http://api.ebulksms.com:8080/sendsms.xml";
35. PostXml requester = new PostXml();
36. theoutput = requester.postXMLData(xmlrequest, theurl);
37. if(theoutput.contains("100")){
38. System.out.println("100");
39. }
40. else{
41. System.out.println(theoutput);
42. }
43. }
44.
45. public String postXMLData(String xmldata, String urlpath){
46. String result = "";
47. try {
48. URL myurl = new URL(urlpath);
49. URLConnection urlconn = myurl.openConnection();
50.
51. urlconn.setRequestProperty("Content-Type", "text/xml");
52. urlconn.setDoOutput(true);
53. urlconn.setDoInput(true);
54. urlconn.connect();
55.
56. //Create a writer to the url
57. PrintWriter pw = new PrintWriter(urlconn.getOutputStream());
58. pw.write(xmldata, 0, xmldata.length());
59. pw.close();
60.
61. //Create a reader for the output of the connection
62. BufferedReader reader = new BufferedReader(new
InputStreamReader(urlconn.getInputStream()));
63. String line = reader.readLine();
64. while (line != null) {
65. result = result + line + "\n";
66. line = reader.readLine();
67. }
68. } catch (Exception e) {
69. e.printStackTrace();
70. }
71. return result;
72. }
73.
74. }

My API Key- 58d7e19946570a4e08adb820dfb6b51f6b440363

Das könnte Ihnen auch gefallen