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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:21:16+00:00 2026-05-27T01:21:16+00:00

I am trying to send a GET request to the Imgur API to upload

  • 0

I am trying to send a GET request to the Imgur API to upload an image.

When I use the following code I receive a 400 status response from the Imgur server – which, according to the Imgur error documentation, means I am missing or have incorrect parameters.

I know the parameters are correct as I have tested them directly in the browser URL (which successfully uploads an image) – so I must not be adding the parameters correctly within the code:

private void addImage(){
    String data = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode("http://www.lefthandedtoons.com/toons/justin_pooling.gif", "UTF-8");
    data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("myPublicConsumerKey", "UTF-8");

    // Send data
    java.net.URL url = new java.net.URL("http://api.imgur.com/2/upload.json");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(data);
    wr.flush();

    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
        Logger.info( line );
    }
    wr.close();
    rd.close();
}

This code is based on the API examples provided by Imgur.

Can anyone tell me what I am doing wrong and how I may resolve the problem?

Thanks.

  • 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-05-27T01:21:17+00:00Added an answer on May 27, 2026 at 1:21 am

    In this sample, imgur service returns 400 Bad Request status response with a non-empty body because of incorrect API key. In case of non successful HTTP response you shold read the response body from an error input stream. For example:

    // Get the response
    InputStream is;
    if (((HttpURLConnection) conn).getResponseCode() == 400)
        is = ((HttpURLConnection) conn).getErrorStream();
    else
        is = conn.getInputStream();
    
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));
    

    And, by the way your example is POST, not GET, because you are sending the parameters in the request body instead of the URL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send a facebook request from the server side api (php). I
I've been trying to use the feature of the imgur API that allows you
I am trying to send get requests to the Google Places API with this
I'm trying to send a GET request to a App Engine server from a
I'm trying to send json string in the get request to the server, here
I'm trying to send a GET request using HttpWebRequest. I've found a lot of
I'm trying to send a HTTP GET request with UDP (since the reply from
Does it send an HTTP GET request for the specified file? I'm trying to
I'm trying to send an http get request via the httplib, but I'm facing
I'm trying to send the node instance JSON data using an ajax get request

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.