2011-12-21 11 views
1

私は次のJava APIを手に入れましたが、APIにバグがあります。 「http://wwwa.way2sms.com/FirstServletsms?custid=」のURLに「FILE NOT FOUND」という例外があります私のAndroidアプリケーションにway2smsを統合する方法

何か提案がありますか?

public class SMS 
{ 
    public void send(String uid, String pwd, String phone, String msg) throws IOException 
    { 
     if ((uid == null) || (uid.length() == 0)) 
     { 
      throw new IllegalArgumentException("User ID should be present."); 
     } 
     uid = URLEncoder.encode(uid, "UTF-8"); 

     if ((pwd == null) || (pwd.length() == 0)) 
     { 
      throw new IllegalArgumentException("Password should be present."); 
     } 
     pwd = URLEncoder.encode(pwd, "UTF-8"); 

     if ((phone == null) || (phone.length() == 0)) 
     { 
      throw new IllegalArgumentException("At least one phone number should be present."); 
     } 
     if ((msg == null) || (msg.length() == 0)) 
     { 
      throw new IllegalArgumentException("SMS message should be present."); 
     } 
     msg = URLEncoder.encode(msg, "UTF-8"); 

     Vector numbers = new Vector(); 

     if (phone.indexOf(59) >= 0) 
     { 
      String[] pharr = phone.split(";"); 
      for (String t : pharr) 
       try { 
        numbers.add(Long.valueOf(t)); 
       } 
       catch (NumberFormatException ex) 
       { 
        throw new IllegalArgumentException("Give proper phone numbers."); 
       } 
     } 
     else 
     { 
      try 
      { 
       numbers.add(Long.valueOf(phone)); 
      } 
      catch (NumberFormatException ex) 
      { 
       throw new IllegalArgumentException("Give proper phone numbers."); 
      } 
     } 

     if (numbers.size() == 0) 
     { 
      throw new IllegalArgumentException("At least one proper phone number should be present to send SMS."); 
     } 
     String temp = ""; 
     String content = "username=" + uid + "&password=" + pwd; 
     URL u = new URL("http://wwwa.way2sms.com/auth.cl"); 
     HttpURLConnection uc = (HttpURLConnection) u.openConnection(); 
     uc.setDoOutput(true); 
     uc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); 
     uc.setRequestProperty("Content-Length", String.valueOf(content.length())); 
     uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
     uc.setRequestProperty("Accept", "*/*"); 
     uc.setRequestProperty("Referer", "http://wwwg.way2sms.com//entry.jsp"); 
     uc.setRequestMethod("POST"); 
     uc.setInstanceFollowRedirects(false); 
     PrintWriter pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream()), true); 
     pw.print(content); 
     pw.flush(); 
     pw.close(); 
     BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream())); 
     while ((temp = br.readLine()) != null) 
     { 
      System.out.println(temp); 
     } 
     String cookie = uc.getHeaderField("Set-Cookie"); 

     br.close(); 
     u = null; 
     uc = null; 


     for (Iterator localIterator = numbers.iterator(); localIterator.hasNext();) 
     { 
      long num = ((Long) localIterator.next()).longValue(); 

      content = "custid=undefined&HiddenAction=instantsms&Action=custfrom450000&login=&pass=&MobNo="+num+ "&textArea="+msg; 
      u = new URL("http://site5.way2sms.com/FirstServletsms?custid="); 


      uc = (HttpURLConnection) u.openConnection(); 
      uc.setDoOutput(true); 
      uc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); 
      uc.setRequestProperty("Content-Length", String.valueOf(content.getBytes().length)); 
      uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
      uc.setRequestProperty("Accept", "*/*"); 
      uc.setRequestProperty("Cookie", cookie); 
      uc.setRequestMethod("POST"); 
      uc.setInstanceFollowRedirects(false); 
      pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream()),true); 
      pw.print(content); 
      pw.flush(); 
      pw.close(); 
      br = new BufferedReader(new InputStreamReader(uc.getInputStream())); 
      while ((temp = br.readLine()) != null) 
      { 
       System.out.println(temp); 
      } 
      br.close(); 
      u = null; 
      uc = null; 

     } 

     u = new URL("http://wwwa.way2sms.com/jsp/logout.jsp"); 
     uc = (HttpURLConnection) u.openConnection(); 
     uc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); 
     uc.setRequestProperty("Accept", "*/*"); 
     uc.setRequestProperty("Cookie", cookie); 
     uc.setRequestMethod("GET"); 
     uc.setInstanceFollowRedirects(false); 
     br = new BufferedReader(new InputStreamReader(uc.getInputStream())); 
     while ((temp = br.readLine()) != null) 
     { 
      System.out.println(temp); 
     } 
     br.close(); 
     u = null; 
     uc = null; 
    } 
} 
+0

まあ、そのURLは(404を返しません – RoToRa

+0

実際にはちょうど私はここにコメントを追加しましたが、まだrplyを持っていません....もしあなたが更新されたAPIを持っているなら...あなたはそれを共有したいと思いますか? ..私は助けてくれるでしょう...ありがとう – user1109610

答えて

0

変更URLに - 。> http://wwwd.way2sms.com/FirstServletsms?custid= "+数....そして、それが動作します