Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1106127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:44:36+00:00 2026-05-17T01:44:36+00:00

I am trying to use Google language detection API, Right now I am using

  • 0

I am trying to use Google language detection API, Right now I am using the sample available on Google documentation as follows:

    public static String googleLangDetection(String str) throws IOException, JSONException{        
        String urlStr = "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=";
//        String urlStr = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Paris%20Hilton";
        URL url = new URL(urlStr+str);
        URLConnection connection = url.openConnection();
//        connection.addRequestProperty("Referer","http://www.hpeprint.com");

        String line;
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        while((line = reader.readLine()) != null) {
         builder.append(line);
        }

        JSONObject json = new JSONObject(builder.toString());

        for (Iterator iterator = json.keys(); iterator.hasNext();) {
            String type = (String) iterator.next();
            System.out.println(type);
        }

        return json.getString("language");
    }

But I am getting http error code ‘406’.

I am unable to understand what the problem is? As the google search query(commented) below it is working fine.

The resultant language detection url itself is working fine when I run it in firefox or IE but it’s failing in my java code.

Is there something I am doing wrong?

Thanks in advance

Ashish

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:44:37+00:00Added an answer on May 17, 2026 at 1:44 am

    Found the answer at following link:

    HTTP URL Address Encoding in Java

    Had to modify the code as follows:

    URI uri = new URI("http","ajax.googleapis.com","/ajax/services/language/detect","v=1.0&q="+str,null);       
    URL url = uri.toURL();  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Google visualization's query language to query for a string using
I'm trying to use Google Guice with the @Inject and @Singleton properties as follows:
I'm trying to use Google Analytics API to query internal searches that happen on
I'm trying to use Google's SDK Tutorial for Android using Eclipse. I was able
I'm trying to use Google's Images API to search an image and put it
I am trying to use the Google Map API- I've successfully managed to add
I'm trying to use the google translate api's to... well translate some text, but
I am trying to use Google Translate REST API and while requesting the following
I am trying to get the Google Adwords API, and right out of the
I am trying to use the google tasks api in a chrome extension, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.