0

다음 코드를 사용하여 검색 결과를 얻으려고 시도했지만 항상 Bad Request이 표시됩니다.빙 검색에서 검색 결과 가져 오기

다음은 코드입니다. 여기

String BingURL = "https://api.datamarket.azure.com/Bing/Search/v1/News?Query=%27"+ City_Name.replace(" ","%20") +"%27"; 
      String accountKey = "abcdefghijklmnopqrstuvwxyz"; 
      HttpClient client = new DefaultHttpClient(); 
      try 
      { 
       HttpGet request = new HttpGet(BingURL); 
       byte[] accountKeyBytes = Base64.encode((accountKey +":" + accountKey).getBytes(), Base64.DEFAULT); 
       String accountKeyEnc = new String(accountKeyBytes); 
       request.setHeader("Authorization", "Basic "+accountKeyEnc); 
       ResponseHandler<String> responseHandler2 = new BasicResponseHandler(); 
       String responseBody = client.execute(request, responseHandler2); 
       response[0] = responseBody; 
       Log.v("Bing Results", responseBody); 
      } 

      catch(Exception e) 
      { 
       e.printStackTrace(); 
      } 

은 사람이 무엇을 제안 할 수있는 로그 캣 출력

01-03 16:21:29.294 22763-22891/samarth.learning.http W/System.err﹕ org.apache.http.client.HttpResponseException: Bad Request 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at samarth.learning.http.MainActivity$MyAsyncTask.doInBackground(MainActivity.java:431) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at samarth.learning.http.MainActivity$MyAsyncTask.doInBackground(MainActivity.java:346) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
01-03 16:21:29.304 22763-22891/samarth.learning.http W/System.err﹕ at java.lang.Thread.run(Thread.java:841) 

입니까?

+0

로그가 좋지 않음을 제안합니다. 귀하의 빙 url을 확인하십시오. –

+0

나는 이미 알고 있습니다. –

답변

2

마지막으로 다음 코드가 유용했습니다.

byte[] accountKeyBytes = Base64.encode((accountKey + ":" + accountKey).getBytes(), Base64.NO_WRAP); 
관련 문제