0

this 웹 서비스에 데이터를 게시하려하지만이 권한을 얻을 수없는 것 같습니다! 그래서 임씨는 서버에 json을 게시하려하지만이를 수행하는 방법을 모른다.서버로 데이터를 보내고 응답을 처리하십시오 - Android

콘텐츠 형식 : 응용 프로그램/JSON HTTPMethod : POST의 HTTPBody : { "CouponVerificationCode": "594952223490", "apiKey에": "zFyWQDYUKXQQpvG86snPD1OSslr7Q6DGEGbQ1f7P2YeTxB56y"나는 JSON의 responce을 얻기 위해이 예제 JSON을 보낼 필요 "토큰": "_ 2_jx1YFvTZGGLNtJBoDW3gDZmNNAGpTWzT7dC6GrNAIkhhX9PWv75b776gq1ZO_2_SxMJjq8_2_kaDMyxX59HczOyaw =="}

대신 내가 html로 responce을 얻을 json으로 responce을 가져 오는. 누군가이 문제를 해결할 수 있도록 도와 줄 수 있습니까?

public static String makeRequest(String path) throws Exception { 

     DefaultHttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httpost = new HttpPost(path); 
     JSONObject holder = new JSONObject(); 
     // holder.accumulate(name, value) 


     String test = "{\"ApiKey\":\"somekey\"," 
       + "\"OperativeSystem\":\"0\"," 
       + "\"AppVersion\":\"1\"," 
       + "\"WebServiceVersion\":\"1\"}"; 
     StringEntity se = new StringEntity(test); 
     Log.v("--", test); 
     httpost.setEntity(se); 
     httpost.setHeader("Accept", "application/json"); 
     httpost.setHeader("Content-type", "application/json"); 

     ResponseHandler responseHandler = new BasicResponseHandler(); 
     String response = httpclient.execute(httpost, responseHandler); 
     // HttpEntity entity = response.getEntity(); 
     Log.v("--", response); 
     return response; 
    } 
+0

당신이 지금 답을 얻고 무엇 당신은 HTML – geekCode

+0

로 변환 구문 분석 할 필요가 .. ?? : 여기 내 작업 코드는 –

+0

를 JSON되지 않는 responce을 @geekCode responce 문자열 – geekCode

답변

0

대신 httpPost의 httpGet를 사용하십시오 :

는 서버와의 통신에 사용할 코드 메신저입니다.

  HttpClient httpclient = new DefaultHttpClient(); 

      // make GET request to the given URL 
      HttpGet httpGet =new HttpGet(url); 
      String User = context.getString(R.string.json_uname); 
      String Password = context.getString(R.string.json_pwd); 
      httpGet.setHeader("Authorization", "Basic "+ new String(Base64.encode((User +":"+ Password).getBytes(),Base64.NO_WRAP))); 

      HttpResponse httpResponse = httpclient.execute(httpGet); 

      // receive response as inputStream 
      inputStream = httpResponse.getEntity().getContent(); 

      // convert inputstream to string 
      if(inputStream != null) 
      { 
       //convertInputStreamToString(inputStream); 
       BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); 
       String json = reader.readLine(); 
       JSONTokener tokener = new JSONTokener(json); 
       finalResult = new JSONArray(tokener); 
      } 
      else 
       finalResult =null; 
관련 문제