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 8179387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:59:22+00:00 2026-06-06T23:59:22+00:00

I am using GET REST call in java using the given code, but I

  • 0

I am using GET REST call in java using the given code, but I am getting an error code : 404 i.e Not Found . But when I am using the same URL in the browser I am getting the output and it is working fine.I new to JAVA.
May be I am passing the query parameters wrongly, but I am not getting it.
I am working in NETBEANS 7.1.2. Please help.

    import java.io.IOException;
    import java.io.OutputStreamWriter; 
    import java.net.HttpURLConnection; 
    import java.net.URL; 
       public class Test {
          private static String ENDPOINT ="http://wisekar.iitd.ernet.in/active/api_resources.php/method/mynode?";
          public static void main(String[] args) throws IOException 
          { 
              URL url = new URL(ENDPOINT + "key=" + "mykey"  );
              HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); 
              httpCon.setDoOutput(true);
              httpCon.setRequestMethod("GET");
             OutputStreamWriter out = new OutputStreamWriter( httpCon.getOutputStream());
             System.out.println(httpCon.getResponseCode());
             System.out.println(httpCon.getResponseMessage());
             out.close(); 
          }
   }

here mykey is the key given to me by the website.

I also want to print the response message on the output window or console. As I want to store it in the future for some extraction.
Please Help.

  • 1 1 Answer
  • 0 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-06-06T23:59:23+00:00Added an answer on June 6, 2026 at 11:59 pm

    Here is your code.. Use it. It is giving response as 401-Unauthorised to me and the same response at browser URL, may this cause of VPN some some other issue. IF you use

    private static String ENDPOINT ="http://google.com"; 
    

    It will give you 200-OK.

    import java.io.IOException;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLEncoder;
    
           public class Test {
              private static String ENDPOINT ="http://wisekar.iitd.ernet.in/active/api_resources.php/method/mynode";
              public static void main(String[] args) throws IOException 
              { 
                  String url = ENDPOINT;
                  String charset = "UTF-8";
                  String param1 = "mykey";
    
                  String query = String.format("key=%s", 
                       URLEncoder.encode(param1, charset));
                  java.net.URLConnection connection = new URL(url + "?" + query).openConnection();
                  connection.setRequestProperty("Accept-Charset", charset);
                  if ( connection instanceof HttpURLConnection)
                  {
                     HttpURLConnection httpConnection = (HttpURLConnection) connection;
                     System.out.println(httpConnection.getResponseCode());
                     System.out.println(httpConnection.getResponseMessage());
                  }
                  else
                  {
                     System.err.println ("error!");
                  }
              }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have writing Java code Using Jersey library to call Rest APIs. For my
I am developing an application in which I am using GET REST call to
Using get/set seems to be a common practice in Java (for various reasons), but
How I stop Jackrabbit using SimpleSecurityManager? I'm trying to call session.getUserManager() but I get
I am using this vb.net code file to call a procedure to get dates
I'm using get_by_id() to read entities from NDB and I do not get it
I'm trying to insert data into the SQLite database using get EditText, but I
i have this simple code to load data from other php page using get
I'm making call to Alfresco Webscripts which return JSON. I do this using GET
I get a page using file_get_contents from a remote server, but I want to

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.