Java找不到PHP脚本,但可以在浏览器中使用

Java找不到PHP脚本,但可以在浏览器中使用,java,php,mysqli,ubuntu-12.10,Java,Php,Mysqli,Ubuntu 12.10,我在/var/www/目录中保存了几个PHP脚本。我可以从浏览器中运行它们,但Java无法看到它们 以下是浏览器的输出: 来自Java: DB: Error executing script: get_profile_ids HTTP/1.1 404 Not Found [Date: Tue, 16 Apr 2013 11:52:40 GMT, Server: Apache/2.2.22 (Ubuntu), Vary: Accept-Encoding, Content-Length: 288,

我在/var/www/目录中保存了几个PHP脚本。我可以从浏览器中运行它们,但Java无法看到它们

以下是浏览器的输出:

来自Java:

DB: Error executing script: get_profile_ids
HTTP/1.1 404 Not Found [Date: Tue, 16 Apr 2013 11:52:40 GMT, Server: Apache/2.2.22 (Ubuntu), Vary: Accept-Encoding, Content-Length: 288, Keep-Alive: timeout=5, max=100, Connection: Keep-Alive, Content-Type: text/html; charset=iso-8859-1]
DB: Result: 
我的Java代码:

public class ServerTest {

    public static void main(String [] args) {

        callPHPScript("get_print_profile_ids", new ArrayList<NameValuePair>());

    }

    public static String callPHPScript(String scriptName, List<NameValuePair> parameters) {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://localhost/" + scriptName);
        String line = "";
        StringBuilder stringBuilder = new StringBuilder();
        try {
            post.setEntity(new UrlEncodedFormEntity(parameters));

            HttpResponse response = client.execute(post);
            if (response.getStatusLine().getStatusCode() != 200)
            {
                System.out.println("DB: Error executing script: " + scriptName);
                System.out.println(response.toString());
            }
            else {
                BufferedReader rd = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent()));
                line = "";
                while ((line = rd.readLine()) != null) {
                    stringBuilder.append(line);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("DB: Result: " + stringBuilder.toString());
        return stringBuilder.toString();
    }
}
公共类服务器测试{
公共静态void main(字符串[]args){
callPHPScript(“获取打印配置文件ID”,new ArrayList());
}
公共静态字符串callPHPScript(字符串scriptName,列表参数){
HttpClient=new DefaultHttpClient();
HttpPost=新的HttpPost(“http://localhost/“+名称);
字符串行=”;
StringBuilder StringBuilder=新的StringBuilder();
试一试{
setEntity(新的UrlEncodedFormEntity(参数));
HttpResponse response=client.execute(post);
如果(response.getStatusLine().getStatusCode()!=200)
{
System.out.println(“DB:执行脚本时出错:“+scriptName”);
System.out.println(response.toString());
}
否则{
BufferedReader rd=新的BufferedReader(新的InputStreamReader(
response.getEntity().getContent());
第“”行;
而((line=rd.readLine())!=null){
stringBuilder.append(行);
}
}
}捕获(IOE异常){
e、 printStackTrace();
}
System.out.println(“DB:Result:+stringBuilder.toString());
返回stringBuilder.toString();
}
}
还有我的PHP脚本:

<?php
include('connect_db.php');
include('tools.php');

$query = 'SELECT id FROM fingerprint_profiles';

$result = mysql_query($query);
echo($result);

?>

有人知道为什么会发生这种情况吗?

这里有个提示:

System.out.println("DB: Error executing script: " + scriptName);
是伐木吗

DB: Error executing script: get_profile_ids
将测试呼叫更改为

callPHPScript("get_profile_ids.php", new ArrayList<NameValuePair>());
callPHPScript(“get_profile_ids.php”,new ArrayList());

您可能会得到一个成功的结果。

您缺少.php,请更改:
HttpPost=新的HttpPost(“http://localhost/“+名称)


HttpPost=新的HttpPost(“http://localhost/“+scriptName+”.php”)

您的Java代码调用
get\u profile\u id
,而您的浏览器屏幕截图显示
get\u profile\u id.php
。将Java代码更改为调用
get\u profile\u ids.php

调用脚本的位置似乎缺少
.php
。您可能有输入错误,浏览器中的php文件显示
get\u print\u profile\u ids
,您正在调用
get\u profile\u ids
。我在不同的机器上使用了所有这些代码,我不认为需要.php…看起来这就是问题所在!但是我不明白,我让所有这些代码在另一台机器上工作,我从来没有把.php放进去。这可能是因为您的另一台机器的配置不同,可以在服务器上自动附加.php。