2012-02-09 39 views
0

私はjava経由でSMSを送信します。問題は、SMSゲートウェイは、どのようにそれが可能であるJavaアプリケーションからこれを呼び出すには、この形式java経由でSMSを送信する

http://push1.maccesssmspush.com/servlet/com.aclwireless.pushconnectivity.listen 
ers.TextListener?userId=xxxxx&pass=xxxx&appid=xxxx&subappid=xxxx&msgtyp 
e=1&contenttype=1&selfid=true&to=9810790590,9810549717&from=ACL&dlrre 
q=true&text=This+is+a+test+msg+from+ACL&alert= 

問題に送信するために私に尋ねるか、それは特別なライブラリを必要としないのですか?それはHttpURLConnectionを使用して仕事をしますか?ありがとうございました。

以下に行ったサンプルコードは正しいです。

URL sendSms1 = new URL("http://push1.maccesssmspush.com/servlet/com.aclwireless.pushconnectivity.listen 
    ers.TextListener?userId=xxxxx&pass=xxxx&appid=xxxx&subappid=xxxx&msgtyp 
    e=1&contenttype=1&selfid=true&to=9810790590,9810549717&from=ACL&dlrre 
    q=true&text=This+is+a+test+msg+from+ACL&alert="); 

URLConnection smsConn1 = 
    sendSms1.openConnection(); 

答えて

1

それはちょうどHTTP呼び出しだ、あなたは(私が期待して、または任意の近代的な言語)Javaで何か特別なことをする必要はありません。適切な文字列*を作成してから、そのURLにHTTPリクエストを行います。

Javaで要求部分を実行する方法の基本を取り上げる必要がある場合は、SunのチュートリアルReading from and Writing to a URLConnectionを見てください。これは組み込みのクラスを使用しています。私は、ファンキーで便利な方法で接続を処理する数十のライブラリがあると確信しています。

*あなたには発生しなかったかもしれない潜在的な問題点 - クエリ文字列の引数はURLエンコードする必要があります。たとえば、textパラメータにある+文字は、エンコードされたスペースです(URLには異なる意味があります)。同様に、パラメータの1つに?文字を送信する場合は、%3Fと表示される必要があります。 URL文字列を安全に構築する方法の例については、HTTP URL Address Encoding in Javaに受け入れられている回答をご覧ください。

+0

のようなものがいくつかの合理的である場合、私はいくつかのコードで更新している@Doyleあなたは確認することができますか? – user837306

-2
URL url = new URL("http://smscountry.com/SMSCwebservice.asp"); 
HttpURLConnection urlconnection = (HttpURLConnection) url.openConnection(); 

[編集]それは、単純なGETリクエストのように見えます

urlconnection.setRequestMethod("POST"); 
urlconnection.setRequestProperty("Content-Type","application/x-www-form-urlenc‌​oded");  
urlconnection.setDoOutput(true); 

OutputStreamWriter out = new OutputStreamWriter(urlconnection.getOutputStream()); 
out.write(postData); 
out.close(); 

BufferedReader in = new BufferedReader(new InputStreamReader(urlconnection.getInputStream())); 

String decodedString; 

while ((decodedString = in.readLine()) != null) { 
    retval += decodedString; 
} 
+0

openConnectionを呼び出した後、配信ステータスメッセージを待つ必要がある場合、そのための方法はありますか? – user837306

+0

私はそうは思わない。それは非同期の単純なHTTP要求です。この 'urlconnection.setRequestMethod(" POST ")のような出力を読むことができます。 \t \t urlconnection.setRequestProperty( "Content-Type"、 "application/x-www-form-urlencoded"); \t \t urlconnection.setDoOutput(true); \t \t OutputStreamWriter out =新しいOutputStreamWriter(urlconnection.getOutputStream()); \t \t out.write(postData); \t \t out.close(); \t \t BufferedReader in = new BufferedReader(\t新しいInputStreamReader(urlconnection.getInputStream())); \t \t String decodedString; \t \t while((decodedString = in。readLine())!= null){ \t \t \t retval + = decodedString; \t \t} –

+0

コードブロックの書式を設定し、そのコードを(コメント内の)解答に編集する方法を学んでください。 –

0

は、あなたがそのような要求を実行するためのApacheのHttpClientのlibararyを使用することができます。 Vogellaのチュートリアルをご覧ください:http://www.vogella.de/articles/ApacheHttpClient/article.htmlサンプルソースコードと説明。あなたがたjava.net.URLライブラリを使用しようとすることができ

0

この

// at this before you need to generate the urlString as "http://push1.maccesssmspush.com/servlet/com.aclwireless.pushconnectivity.listen 
ers.TextListener?userId=xxxxx&pass=xxxx&appid=xxxx&subappid=xxxx&msgtyp 
e=1&contenttype=1&selfid=true&to=9810790590,9810549717&from=ACL&dlrre 
q=true&text=This+is+a+test+msg+from+ACL&alert=" 

URL url = new URL(urlString); 
// send sms 
URLConnection urlConnection = url.openConnection();// open the url 
// and you, also can get the feedback if you want 
BufferedReader br = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream())); 
+0

はい私は配信ステータスを取得する必要があります。バッファリングされた読者がここで役に立つでしょう。urlの一部として、配信ステータスを得るためにdlrreq = trueを送信する必要があります。 – user837306

関連する問題