2017-11-23 3 views
2

몇 가지 프로젝트에 간단한 API를 사용하고 있지만 응용 프로그램에서 GET 요청을하면 응답 코드 400이 반환됩니다. 문제 해결에 도움이 될 것입니다. .400 응답 코드를 반환하는 HTTP GET 요청

내 코드는 :

URL oracle = new URL(URL+"SELECT `name`, `username`, `email`, `position`, `status` FROM `"+pl.APIKEY+"` WHERE 1"); 
      HttpURLConnection con = (HttpURLConnection) oracle.openConnection(); 
      con.setRequestProperty("Content-Type", "text/plain; charset=utf-8"); 
      con.setRequestMethod("GET"); 
      con.setDoOutput(false); 
      BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream())); 


      String inputLine; 
      int size = 0; 
      String position=null ,user = null,email= null,name= null; 
      int status = 0; 
      while (true){ 
       inputLine = in.readLine(); 
       if(inputLine == null){ 
        break; 
       } 
       System.out.println(inputLine); 
       String[] input = inputLine.split("`"); 
       user = input[0]; 
       email = input[1]; 
       name = input[2]; 
       position= input[3]; 
       status = 0; 
      } 

나는 내가 잘못했고, 당신은 아무것도 그렇게 말 주시기 바랍니다 감사를 다시 볼 그래서 만약 아무것도 발견 것에 대해 주위를 둘러 보았다했습니다!

답변

1

문제는 귀하의 URL에 있다고 생각합니다. 이 부분을 인코딩해야합니다

", position, email, username, name"+pl.APIKEY+" FROM status을 선택 WHERE 1"

예를 들어 이에 대한 사용 URLEncoder :

URL oracle = new URL(URL+ URLEncoder.encode("SELECT `name`, `username`, `email`, `position`, `status` FROM `"+pl.APIKEY+"` WHERE 1"), "UTF-8")); 
+0

감사합니다 내 문제가 해결 됐어! –

+0

당신은 오신 것을 환영합니다! –