0
我在寫一個Java程序,它可以使用Kannel發送SMS。我在虛擬機Vare虛擬機(Red Hat)中配置了Kannel。 Kannel工作正常,我可以通過鍵入網址發送短信Java程序中的響應代碼錯誤將短信發送到信道
http://192.168.214.128:13013/cgi-bin/sendsms?
username=tester&password=foobar&to=03478847037&text=Mahtab
在我的Windows瀏覽器中。但是,當我通過Java程序訪問同一個網址 我得到這個例外
java.io.IOException: Server returned HTTP response code: 400` for URL:
http://192.168.214.128:13013/cgi-bin/sendsms?
username=tester&password=foobar&to=03478847037&text=Mahtab
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
但當我粘貼瀏覽器相同的URL字符串我能發送短信。
代碼附加
URL url = new URL("http://192.168.214.128:13013/cgi-bin/sendsms?username=tester&password=foobar&to=03478847037&text=Mahtab");
System.out.println(param.toString());
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
StringBuffer answer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {answer.append(line);}
writer.close();
reader.close();
System.out.println(answer.toString());
現在,請幫我在這方面,我缺少的是什麼???
Perhps用戶代理丟失/無效。你應該用_Wireshark_檢查這個結果並比較結果。 – Thor
如果我將jsp頁面中的響應重定向到相同的URL。它是成功的,但它只給我一個錯誤,當我嘗試通過上面的代碼訪問它...........實際上重定向響應並不能解決我的問題,因爲我需要發送批量短信到許多數字這就是爲什麼我要求提到的網址。 –
我認爲沒有必要指定用戶代理....因爲這段代碼被別人成功地使用了......你可以檢查它[這裏](http://stackoverflow.com/questions/10194047)/sending-arabic-sms-in-kannel) –