2013-12-10 4 views
0

나는 안드로이드에서 일부 문자열 값을 recevive php url을 호출합니다.
내 안드로이드 코드는 다음과 같습니다 : 내가 안드로이드는 null받을PHP는 android에 null http 응답을 반환

<?php 

echo "kunal"; 
?> 

실행 후 :

 private static final String BASE_URL="http://10.10.2.26/demo"; 
public static HttpResponse executeUrl(String action,String[] parameters) { 


    try { 
     HttpClient client = new DefaultHttpClient(); 



     URI website = new URI(BASE_URL+"/"+action); 


     System.out.println("serverurl="+website); 
     HttpGet request = new HttpGet(); 


     request.setURI(website); 

     System.out.println("5"); 
     HttpResponse response = client.execute(request); 


     System.out.println("no error in execute URL"); 
     return response; 
    } catch (Exception e) {   

     System.out.println("In error of execute URL"+e.getLocalizedMessage()); 
    } 
    return null; 
} 

다음은 내 PHP 코드입니다.

+0

당신의 PHP 코드 – Manitoba

+0

을 올리십시오. 코드를 추가했지만 표시되지 않았습니다. 내 코드는

+0

귀하의 IP는 로컬 주소입니다. – Manitoba

답변

1

PHP에서 값을 검색하기위한 코드. 잘 작동합니다.

private void get_valueFromPhp(String php) { 
    String responseString = null; 

    try{  
     HttpClient httpclient = new DefaultHttpClient(); 
     String url ="your url"; 
     HttpPost httppost = new HttpPost(url); 
     HttpResponse response = httpclient.execute(httppost); 

     ByteArrayOutputStream out = new ByteArrayOutputStream(); 
     response.getEntity().writeTo(out); 
     out.close(); 
     responseString = out.toString(); 
     Toast.makeText(getApplicationContext(),responseString,1000).show(); 
    } catch(Exception e) { 
    } 
} 
+0

감사합니다. –

+0

@Kunal Kor : 안녕하세요. 해피 코딩. – Shahina

1

은 URL을 열어보십시오 : 귀하의 휴대 전화 브라우저

http://10.10.2.26/demo 

. 아마도 당신은 같은 네트워크에 있지 않습니다.

+0

현재 에뮬레이터에 랩톱에서 실행 중입니다. URL이 내 휴대 전화 브라우저에서 올바르게 실행되고 있습니다. –