2013-04-16 2 views
0

내/var/www/디렉토리에 여러 개의 PHP 스크립트가 저장되어 있습니다. 내 브라우저에서 실행할 수는 있지만 Java에서는 볼 수 없습니다.Java에서 PHP 스크립트를 찾을 수 없지만 브라우저에서 작동합니다.

enter image description here

그리고 자바에서 :

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: 

내 자바 코드 :

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(); 
    } 
} 

그리고 내 PHP 스크립트 :

여기

브라우저에서 출력됩니다

왜 이런 일이 일어날 지 아무도 알지 못합니까 ??

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

System.out.println("DB: Error executing script: " + scriptName); 

DB: Error executing script: get_profile_ids 

변화를 테스트 호출을 기록하고 당신은 가능성이 성공적인 결과를 얻을 수 있습니다 :

+0

스크립트를 호출하는 곳에서'.php '가 누락 된 것처럼 보입니다. – NilsH

+0

당신은 오타가있을 수 있습니다. 브라우저의 PHP 파일에'get_print_profile_ids'라고 쓰여 있는데,'get_profile_ids'를 호출하고 있습니다 ... – akluth

+0

나는이 코드를 다른 컴퓨터에서 작동 시켰습니다. 나는 .php가 필요하다고 생각하지 않습니다. .. – TomSelleck

답변

5

당신은 .PHP, 변화를 누락 : 브라우저의 스크린 샷 get_profile_ids.php을 표시하면서
HttpPost post = new HttpPost("http://localhost/" + scriptName);

HttpPost post = new HttpPost("http://localhost/" + scriptName + ".php");

+0

그것은 이것이 문제인 것처럼 본다! 나는이 코드가 다른 컴퓨터에서 작동한다는 것을 이해하지 못한다. 나는 절대로 .php를 넣지 않았다. – TomSelleck

+0

다른 컴퓨터가 다르게 구성되어 서버에 .php를 자동으로 추가 할 수있다. –

1

자바 코드는 get_profile_ids를 호출합니다. Java 코드를 get_profile_ids.php으로 변경하십시오.

+0

죄송합니다. 테스트 코드의 오타가 수정되었습니다. – TomSelleck

관련 문제