Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve the HTTP 414 “Request URI too long” error in android / base64 image?

Tags:

android

http

I am trying to pull an base64 encoded image from my app to database(which is in my server), but I get this error.

the server responded with a status of 414 (Request-URI Too Long)

I know that for URLs, shortening them fixes the error but I can't shorten a base64 string.

How to fix this one.

HttpGet httpGet = new HttpGet(URL);

try {

 HttpResponse response = httpClient.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream inputStream = entity.getContent();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(inputStream));
            String line;
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
            }
            inputStream.close();
        } else {
            Log.d("JSON", "Failed to download file");
        }
    }
like image 434
Karthik Avatar asked Oct 15 '25 14:10

Karthik


1 Answers

Try Retrofit. Use @FormUrlEncoded in retrofit and @POST("ur_api_name") and send the data using @Field("data") annotation.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!