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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:46:28+00:00 2026-05-26T11:46:28+00:00

I am trying to write a small class using the Apache HttpClient library that

  • 0

I am trying to write a small class using the Apache HttpClient library that would do an HTTPS post to a specified URL sending some XML. When I run my code, the HTTP status line I receive back is “403 Service Error”. Here’s the complete error HTML returned:

$errorDump  java.net.SocketTimeoutException:Read timed out
$errorInfo  
$errorDump  java.net.SocketTimeoutException:Read timed out
$error  Read timed out
$localizedError Read timed out
$errorType  java.net.SocketTimeoutException
$user   
$time   2011-10-25 09:39:29 EDT
$error  Read timed out
$errorType  java.net.SocketTimeoutException

This is the code I am using:

import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class HttpXmlPost {

    public static void main(String[] args)
    {
        String url = "https://someurlhere.com";
        String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><xmlTag></xmlTag>";

        String content = request(xmlStr, url);
        System.out.println(content);
    }

    private static String request(String xmlStr, String url) {
        boolean success = false;
        String content = "";

        HttpClient httpclient = new DefaultHttpClient();

        try {
            HttpPost httpPost = new HttpPost(url.trim());

            InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(xmlStr.getBytes() ), -1);
            reqEntity.setContentType("application/xml");
            reqEntity.setChunked(true);

            httpPost.setEntity(reqEntity);

            System.out.println("Executing request " + httpPost.getRequestLine());
            HttpResponse response = httpclient.execute(httpPost);
            HttpEntity resEntity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if(response.getStatusLine().getStatusCode() == 200){
                success = true;
            }
            if (resEntity != null) {
                System.out.println("Response content length: " + resEntity.getContentLength());
                System.out.println("Chunked?: " + resEntity.isChunked());
            }

            BufferedReader reader = new BufferedReader(new InputStreamReader(resEntity.getContent()));
            StringBuilder buf = new StringBuilder();
            char[] cbuf = new char[ 2048 ];
            int num;

            while ( -1 != (num=reader.read( cbuf ))) {
                buf.append( cbuf, 0, num );
            }

            content = buf.toString();

            EntityUtils.consume(resEntity);
        } 
        catch (Exception e) {
            System.out.println(e);
        }
        finally {
            httpclient.getConnectionManager().shutdown();
        }

        return content;
    }
}

Whatever XML I pass in doesn’t seem to matter, it gives the same error no matter what. Note that this actually works with some URLs. For example, if I put https://www.facebook.com, it goes through. However, it doesn’t work for my specified URL. I thought it might be a certificate issue, tried to add some code to trust any certificate, didn’t seem to work either, though I may have done it wrong. Any help is appreciated.

  • 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-26T11:46:28+00:00Added an answer on May 26, 2026 at 11:46 am

    Based on the SocketTimeoutException in the first line of the response HTML, I’m guessing that the component which implements the handler for the URL to which you are posting is having some connection problems to a source system it needs to generate the response data.

    Basically, it looks like the problem is on the server, not your client.

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

Sidebar

Related Questions

I'm trying to write a small class library for a C++ course. I was
Continuing to learn WCF, I'm trying to write a small program that would with
I'm trying to write a small app that monitors how much power is left
I'm trying to write a small application that needs to use the clipboard for
I am trying to write a small application using bouncycastle algorithm, from the BouncyCastleProvider.java
I'm trying to send some small data over UDP using the AsyncUdpSocket library .
I'm trying to write a small webserver that accepts Http requests and returns Http
I am trying to write a small java program that will accept a file
I am trying to write a small media player using GTK+ and GStreamer and
Trying to write a small function that updates a paragraph with an image's alt

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.