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

  • Home
  • SEARCH
  • 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 7544871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:47:08+00:00 2026-05-30T08:47:08+00:00

I send POST request to create some data resource on server. I get Response

  • 0

I send POST request to create some data resource on server. I get Response Code 201 – all is OK. But I also need to get 2 headers from the response. Those headers contain attributes of the created resource. I did not find the way how to do it using ConnectionRequest’s API.

The class has readHeaders(connection) and getHeader(connection) protected methods. But I could not use them when I got the response – got an exception.

My code example is shown below:

ConnectionRequest reqresp = new ConnectionRequest () {
    protected  void buildRequestBody (java.io.OutputStream os) {
    Logger.inst ().write ("buildRequestBody");
        final String body = "Dummy Request Body"; // necessary for my request
        try {
            os.write (body.getBytes () );
        }
        catch (Exception ex) {
            final String errMsg = ex.toString ();
            Logger.inst ().write (errMsg);
            throw new RuntimeException (errMsg);
        }
    }

    protected void readResponse (InputStream input) throws IOException  {
        // Actually this method will not be called.
        Logger.inst ().write ("readResponse");
        String respText;
        try {
            respText = Util.readToString (input);
        }
        catch (Exception ex) {
            final String errMsg = ex.toString ();
            Logger.inst ().write (errMsg);
            throw new RuntimeException (errMsg);
        }
        Logger.inst ().write (respText);
    }
};
reqresp.setUrl ("MY SERVER URL");
reqresp.setPriority (ConnectionRequest.PRIORITY_HIGH);
reqresp.setPost (true);
reqresp.addRequestHeader ("header1", "val1");
reqresp.addRequestHeader ("Content-type", "application/json");
reqresp.addResponseCodeListener (new ActionListener () {
        public void actionPerformed (ActionEvent ae) {
            Logger.inst ().write ("ResponseCodeListener:");
            Logger.inst ().write (ae.toString () );
            if (ae instanceof NetworkEvent) {
                NetworkEvent evt = (NetworkEvent)ae;
                Logger.inst ().write ("message: " + evt.getMessage () );
                Logger.inst ().write ("response code: " + evt.getResponseCode () );
            }
        }
    });
reqresp.addResponseListener (
    new ActionListener () {
        public void actionPerformed (ActionEvent ae) {
            Logger.inst ().write ("ResponseCodeListener:");
            Logger.inst ().write (ae.toString () );
            if (ae instanceof NetworkEvent) {
                NetworkEvent evt = (NetworkEvent)ae;
                Logger.inst ().write ("message: " + evt.getMessage () );
                Logger.inst ().write ("response code: " + evt.getResponseCode () );
            }
        }
    }
);

NetworkManager.getInstance ().addToQueue (reqresp);
  • 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-30T08:47:09+00:00Added an answer on May 30, 2026 at 8:47 am

    I could not perform the task using the LWUIT’s IO. But I did it easily using the MIDP’s HTTPConnection and met no problems.

    One small comment about the MIDP’s HTTPConnection API. It’s synchronous. So, I did not want to use it in the main GUI thread. Moreover, the API is low-level. So, I had to implement some kind of wrapper to hide the details and to execute HTTP request asynchronously in a separate thread.

    Now one comment about the LWUIT’s IO ConnectionRequest class. I found it programmer-unfriendly. It represents both a request and response. So, it’s not clear what the methods are related to the request and what to the response.

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

Sidebar

Related Questions

.ajax() can send a post request and get data in return where as .load()
Code exemple: HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(http://some.existing.url); request.Method = POST; request.ContentType = text/xml; Byte[] documentBytes
I want to post some data to the server, and in response, I want
I have a program to send POST request to a server. I'm using cURL
How to send an http request with either post/get method using javascript as an
I want to send post request to some service using Java. Requests must contain
I am trying to send a POST request to add some content to an
I would like to know how to send a post request in curl and
Trying to find a way to send a POST HTTPS request from Python to
I have to send a request as https post to a third party Apache

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.