![](/img/trans.png)
[英]Getting Error while running program on linux. On windows it is working fine
[英]getting error in HTTPURLConnection while running program on linux server
我正在運行的progrom已成功在我的本地計算機上運行(成功200正常),但是當我將其上傳到linux Web服務器時,卻收到404錯誤代碼。
我的代碼是:
try{
String url = "http://sms.bazaardekho.com/ComposeSMS.aspx";
String charset = "UTF-8";
String username = "shaillu";
String priority="1";
String dnd="1";
String unicode="0";
String query = String.format("username=%s&priority=%s&dnd=%s&unicode=%s",
URLEncoder.encode(username, charset),
URLEncoder.encode(priority, charset),
URLEncoder.encode(dnd, charset),
URLEncoder.encode(unicode, charset));
URL oracle = new URL(url + "?" + query);
HttpURLConnection yc =(HttpURLConnection) oracle.openConnection();
yc.setRequestMethod("GET");
yc.setConnectTimeout(3000);
yc.setRequestProperty("Accept", "*/*");
yc.setRequestProperty("User-Agent", "PARSHWA WEB SOLUTIONS");
yc.setRequestProperty("Accept-Charset", charset);
out.println(yc.getRequestMethod());
out.println(yc.getResponseCode());
out.println(yc.getResponseMessage());
out.println("<br/>ErrorStream :"+yc.getErrorStream());
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
out.println(inputLine);
in.close();
}catch(Exception e){out.println("Exception:" + e);}
輸出:
GET 404 Not Found
ErrorStream :sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@33a719 Exception:java.io.FileNotFoundException: http://sms.bazaardekho.com/ComposeSMS.aspx?username=shaillu&priority=1&dnd=1&unicode=0
該程序已在本地計算機上成功運行,但是當我嘗試在用於我的網站的在線服務器上運行該程序時,出現此錯誤。 請告訴我這個錯誤的原因以及如何解決。
謝謝。
您確定自己是小馬,而且可能是Windows HttpURLConnection僅指該類sun.net.www.protocol.http.HttpURLConnection
在Linux上,我默認使用JDL提供的類。 系統范圍的屬性設置為smewhere或eclipse為您完成:)
你能嘗試改變這個嗎
yc.setRequestProperty("User-Agent", "PARSHWA WEB SOLUTIONS");
至
yc.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.