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

AsyncTask를 통해 전달하는 인자값 쓰레기값처리좀 알려주세요 ㅠ

0 추천

url값을 param 값으로 전달하는데 java.net.MalformedURLException: Protocol not found: http%3A%2F%2F211.226.214.248%2Fgetinfo.php
이런 에러가 뜹니다 ㅠㅠ 해결방법없을까요?

 

final String url = "http://211.226.214.248/getinfo.php";
gPHP.execute(url,acode);
class GettingBlindWings extends AsyncTask<String, Integer, String> {
    @Override
    // php에서 데이터를 읽어옴
    protected String doInBackground(String... params) {
        StringBuilder jsonHtml = new StringBuilder();

        try {
            URL phpUrl = new URL(params[0]);
            String body = "&acode=" + params[1];
            HttpURLConnection conn = (HttpURLConnection) phpUrl.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            OutputStream os = conn.getOutputStream();
            os.write(body.getBytes("utf-8"));
            os.flush();
            os.close();
            //BufferedReader br = new BufferedReader( new InputStreamReader( conn.getInputStream(), "EUC-KR" ), conn.getContentLength() );
            String buf;

            if (conn != null) {
                if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {

                    BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"), conn.getContentLength());
                    while (true) {
                        String line = br.readLine();
                        if (line == null)
                            break;

                        Log.d("line", line);
                        jsonHtml.append(line + "\n");
                    }
                    br.close();
                }
                conn.disconnect();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.d("jsonHTML", jsonHtml.toString());

        return jsonHtml.toString();
    }

    // 가져온 데이터를 이용해 개발자가 원하는 일을 작성
    public void onPostExecute(String str) {
        try {
            JSONArray results;
            results = new JSONArray(str);
            for (int i = 0; i < results.length(); i++) {
                JSONObject temp = results.getJSONObject(i);
                blindwings = temp.getString("blindWings");
                blindAutoUnauto = temp.getString("blindAutoUnauto");
                if(blindwings.equals("open"))wings.setBackgroundResource(R.drawable.sun);
                else wings.setBackgroundResource(R.drawable.clound);

                if(blindAutoUnauto.equals("auto"))AutounAuto.setText("Auto");
                else AutounAuto.setText("UnAuto");


            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
익명사용자 님이 2017년 6월 7일 질문
HTTP통신은 대부분의 사람들이 직접 구현하지 않고 volley나 retrofit을 많이 사용하고 있습니다
timeout, network error등을 직접 컨트롤 하지 않아도 되서 편리하니 한번 고려해 보세요

답변 달기

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