我正在运行一个在我的本地机器上成功运行的progrom(Success 200 Ok)但是当我将它上传到我的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
此程序在我的本地计算机上成功运行,但是当我尝试在我的在线服务器上运行此程序以用于我的网站时,我收到此错误。 请告诉我这个错误的原因&amp;我该如何解决这个问题。
谢谢。
答案 0 :(得分:0)
你肯定在你的loal和大概是windows HttpURLConnection只引用了这个类sun.net.www.protocol.http.HttpURLConnection
在linux上它默认为JDL提供了我相信的课程。一个系统范围的属性设置smewhere或eclipse为你做这个:)
答案 1 :(得分:0)
请您尝试更改此
yc.setRequestProperty("User-Agent", "PARSHWA WEB SOLUTIONS");
到
yc.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");