마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

android에서 php로 데이터 전송관련

0 추천
Spinner에서 데이터를 전송해서 받아오려고 합니다.

선택한 스피너의 값을 전송해서 php를 통해 json 데이터를 받아오는데

데이터값이 자꾸 전송이안되는거같네요...

java acitivity 에서 전송하는 부분입니다.

protected Void doInBackground(String... params) {

            String selectedItem = params[0].toString();
            ServiceHandler jsonParser = new ServiceHandler();
            
            
            try {
                //URL 설정, 접속
                URL url = new URL("접속URL");
                HttpURLConnection http = (HttpURLConnection)url.openConnection();
                
                //전송 모드 설정
                http.setDefaultUseCaches(false);
                http.setDoInput(true);  //서버에서 읽기모드 지정
                http.setDoOutput(true); //서버에서 쓰기모드지정
                http.setRequestMethod("POST");
                
                http.setRequestProperty("content-type", "application/json");
                
                //서버로 값 전송
                StringBuffer buffer = new StringBuffer();
                buffer.append("path1").append("=").append(selectedItem);
                
                OutputStreamWriter outStream = new OutputStreamWriter(http.getOutputStream(), "UTF-8");
                PrintWriter writer = new PrintWriter(outStream);
                writer.write(buffer.toString());
                writer.flush();
                
                String json = jsonParser.makeServiceCall(URL_DEP_RESULT, ServiceHandler.POST);
                Log.e("Dep_result json : ", "> "+json);
                
                if(json != null) {
                    try {
                        JSONObject jsonObj = new JSONObject(json);
                        if(jsonObj != null) {
                            JSONArray dep_result = jsonObj.getJSONArray("dep_result");
                            
                            for(int i=0; i<dep_result.length(); i++) {
                                JSONObject dep_resObj = (JSONObject)dep_result.get(i);
                                Dep_result dep_res = new Dep_result(dep_resObj.getString("dep_file"));
                                fileList.add(dep_res);
                            }
                        }
                    } catch(JSONException e) {
                        Log.e("Json Error : ", e.toString());
                    }
                } else {
                    Log.e("Depfile if Error : ", "IF ERROR");
                }
                
            } catch(Exception e) {
                e.printStackTrace();
            }
            return null;

php 부분입니다.

<?php
    
    $path1 = $_POST["path1"];
    
    function getPath2List($path1) {
        
        $dir="01/".$path1;
        
        $files = scandir($dir);
        $file_path = array();
        
        $file_path["dep_result"] = array();
            
        foreach($files as $ind_file) {
            if($ind_file != '.' && $ind_file !='..'){
                
                if(substr($ind_file,0,2) == "20") {
                
                    if($path1 == "") {
                        $tmp = array();
                        $tmp["dep_file_nopath"] = $ind_file;
                    } else {
                        $tmp = array();
                        $tmp["dep_file"] = $ind_file;
                    }
                }
            array_push($file_path["dep_result"], $tmp);
            
            }
        }
        
        header('Content-Type: application/json');
    
        echo json_encode($file_path);
        
    }
    getPath2List($path1);

?>

위에 보시면 테스트용으로 받아오는 $path1이 없을때 json 데이터가 출력이 됩니다. 아직초보라 좀알려주세요ㅠㅠ
eorl0533 (160 포인트) 님이 2016년 6월 9일 질문
eorl0533님이 2016년 6월 9일 수정

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...