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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:29:23+00:00 2026-05-21T22:29:23+00:00

I tired to connect my app with the remote server and pass few credentials

  • 0

I tired to connect my app with the remote server and pass few credentials to it, but i am always getting a same response from the server. I tried changing all the parameter value and other request header values that i am passing, but still i can’t reach the exact solution. I need to you, whether am i using the correct way to ping with the server and to pass the values.

Below is the code that i am using , Please let me know if i have gone wrong somewhere.

// HttpServiceConnection.java

import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.HttpsConnection;

import net.rim.device.api.system.DeviceInfo;

import com.beacon.bb.app.util.WSMConfig;

/**
* @author N********
* 
*/
public class HttpServiceCommunication {

public HttpServiceCommunication() {
    System.out.println("Http Service Communication Called");
}

public String sendHttpPost(String uri, String email, String uid,
        String pass) throws Exception { // Hashtable header
    String response = null;
    // create the connection...
    System.out.println("Url    " + uri);
    HttpConnection _connection = null;
    String params = null;
    if (DeviceInfo.isSimulator()) {
        params = ";deviceside=false";
    } else {
        params = ";deviceside=true;interface=wifi";
    }

    String URL = uri + params;
    System.out.println("Connecting to Http Connection ");
    try {
    _connection = (HttpConnection) Connector.open(URL);
    } catch(Exception e){
        e.printStackTrace();
    }

    if (_connection != null) {

        _connection.setRequestMethod(HttpConnection.POST);
        System.out.println("After Request Method ");
        _connection.setRequestProperty("User-Agent",
                "Profile/MIDP-2.0 Configuration/CLDC-1.1");
        _connection.setRequestProperty("Content-Language", "en-US");
        _connection.setRequestProperty("Content-type", "application/json");

        // setting header if any
        // if (header != null) {
        // for (Enumeration en = header.keys(); en.hasMoreElements();) {
        // String key = (String) en.nextElement();
        // String value = (String) header.get(key);
        // _connection.setRequestProperty(key, value);

        _connection.setRequestProperty("email", email);
        //_connection.setRequestProperty("method","login");
        _connection.setRequestProperty("uid", uid);
        _connection.setRequestProperty("password", pass);

        //_connection.setRequestProperty("uid", uid);

        // }
        // }
        System.out.println("Open Output Stream  ");
        // System.out.println("Data is     "+data);
        OutputStream _outputStream = _connection.openOutputStream();
        //System.out.println("Writing data  ");
        //_outputStream.write(data);
        // _outputStream.flush(); // Optional, getResponseCode will flush

        // Getting the response code will open the connection, send the
        // request, and read the HTTP response headers.
        // The headers are stored until requested.
        try {
        System.out.println("Response Code :" + _connection.getResponseCode());
        int rc = _connection.getResponseCode();
        System.out.println("Response Code :" + rc);
        System.out.println("Response Code   :" + rc + " if HTTP OK    :"
                + (rc == HttpConnection.HTTP_OK));
        if (rc == HttpConnection.HTTP_FORBIDDEN) {
            System.out.println("FORBIDDEN");
            response = WSMConfig.NOT_AUTH;
        } else if (rc != HttpConnection.HTTP_OK) {
            response = WSMConfig.NOT_OK;
        } else if (rc == HttpConnection.HTTP_OK) {
            InputStream _inputStream = _connection.openInputStream();
            final int MAX_LENGTH = 128;
            byte[] buf = new byte[MAX_LENGTH];
            int total = 0;
            while (total < MAX_LENGTH) {
                int count = _inputStream.read(buf, total, MAX_LENGTH
                        - total);
                if (count < 0) {
                    break;
                }
                total += count;
            }
            response = new String(buf, 0, total);
            //ByteBuffer bb = new ByteBuffer(_inputStream);
            //response = bb.getString();
            System.out.println("Response from Server   :" + response);
            // close everything out
            {
                if (_inputStream != null)
                    try {
                        _inputStream.close();
                    } catch (Exception e) {
                    }
                if (_outputStream != null)
                    try {
                        _outputStream.close();
                    } catch (Exception e) {
                    }
                if (_connection != null)
                    try {
                        _connection.close();
                    } catch (Exception e) {
                    }
            }
        }
     else {
        response = WSMConfig.SERVER_ERROR;
    }
    }catch(Exception e){
        e.printStackTrace();
    }

}
    //System.out.println("Response :" + response);
    return response;

}

}

I am getting a response like {"code":0,"err":"Missing 'method'."}

Any Help is Appreciable….

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-21T22:29:23+00:00Added an answer on May 21, 2026 at 10:29 pm

    Try this out when you’re wanting to pass data to the server:

    //encode your data to send
    URLEncodedPostData encoder = new URLEncodedPostData(null, false);
    encoder.encode("email", email);
    encoder.encode("method", "login");
    encoder.encode("uid", uid);
    encoder.encode("password", pass);
    
    //Now you open up an output stream to write to the connection
    OutputStream os = _connection.openOutputStream();
    os.write(encoder.getBytes();
    os.flush();
    

    And then continue with the rest of your logic

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

Sidebar

Related Questions

I tried to run a PyQt4 app, but got following error: cannot connect to
I have an app in java that is nothing but a remote server.The remote
Locally I connect to Northwind.mdf but when I upload application to remote server then
In my code i tried to connect signal from QTrayIcon object and my form
I am tring to connect a remote server via openvpn using C#. I am
I'm trying to connect from a web app to another web app using the
I've got a simple task for now: connect to a remote server and get
I am trying to connect to the database but I am getting this exception:
I tried to upload file with connect-form , but if i want to upload
I'm trying to connect to the Twitter API via an AS3 app, but I

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.