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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:43:31+00:00 2026-06-11T17:43:31+00:00

While connecting to https server by skipping the SSL certificates(I mean allow all hosts)

  • 0

While connecting to https server by skipping the SSL certificates(I mean allow all hosts) .
After loggin in to such https server do we need to login everytime to fire get or post requests.

I am trying this in android.
Any good pointers would be helpful.

Login to https server using httpclient(Skip SSL by allowing all)
Fire the simple Get request after login.

Is there any sample code base for this simple scenario.

  • 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-06-11T17:43:32+00:00Added an answer on June 11, 2026 at 5:43 pm

    First of all you have to place your code in an async task as network calls don’t run on the main thread.

    Then you can use this something like this:

    private RegistrationInfo AsyncRegisterDevice(
                    AndroidDeviceInfo deviceInfo, NetworkIdentification networkId, long NMEC) {
                RegistrationInfo reqResp = new Objects().new RegistrationInfo();
    
                try {
    
                    JSONStringer deviceRegistration = new JSONStringer().object()
                            .key("DeviceInfo").object().key("androidId")
                            .value(deviceInfo.androidId).key("imei")
                            .value(deviceInfo.imei).key("mac")
                            .value(deviceInfo.mac).key("brand")
                            .value(deviceInfo.brand).key("product")
                            .value(deviceInfo.product).key("model")
                            .value(deviceInfo.model).key("manufacturer")
                            .value(deviceInfo.manufacturer).key("device")
                            .value(deviceInfo.device).key("serial")
                            .value(deviceInfo.serial).key("carrierNumber")
                            .value(deviceInfo.carrierNumber).endObject()
                            .key("UserIdentification").object().key("userName")
                            .value(networkId.username).key("password")
                            .value(networkId.password).endObject()
                            .key("nmec").value(NMEC).endObject();
    
                    HttpPost request = new HttpPost(hostProtocol + "://"
                            + hostAddress + "/Services/Register.svc/Register");
                    request.setHeader("Accept", "application/json");
                    request.setHeader("Content-Type", "application/json");
    
                    StringEntity requestEntity = new StringEntity(
                            deviceRegistration.toString());
    
                    request.setEntity(requestEntity);
    
                    DefaultHttpClient httpClient = (DefaultHttpClient) CSRHttpClient
                            .getNewHttpClient();
    
                    String message = new String();
                    HttpEntity responseEntity = null;
    
                    try {
                        HttpResponse httpResponse = httpClient.execute(request);
                        responseEntity = httpResponse.getEntity();
                    } catch (Exception ex) {
                        message = ex.getMessage();
                        android.util.Log.e("CSR", message);
                        return new Objects().new RegistrationInfo();
                    }
    
                    if (responseEntity == null)
                        return reqResp;
    
                    char[] buffer = new char[(int) responseEntity
                            .getContentLength()];
                    InputStream stream = responseEntity.getContent();
                    InputStreamReader reader = new InputStreamReader(stream);
                    reader.read(buffer);
                    stream.close();
    
                    JSONObject jsonRegInfo = new JSONObject(new String(buffer));
    
                    long androidId = jsonRegInfo.getLong("androidRegistrationId");
                    long userId = jsonRegInfo.getLong("userRegistrationId");
                    String token = jsonRegInfo.get("registrationToken").toString();
    
                    reqResp.androidRegistrationId = androidId;
                    reqResp.registrationToken = token;
                    reqResp.userRegistrationId = userId;
    
                } catch (JSONException jsonEx) {
                    String message = jsonEx.getMessage();
                }
    
                catch (NullPointerException n) {
                    String message = n.getMessage();
                } catch (Exception ex) {
                    String message = ex.getMessage();
                }
                return reqResp;
            }
        }
    

    This code makes a JSon request to a WCF webservice and gets a JSon response which is parsed in the end to a specific object that is then returned.

    public class CSRHttpClient {
    
        public static HttpClient getNewHttpClient()
        {
            try
            {
                KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
                trustStore.load(null, null);
    
                SSLSocketFactory sf = new CSRSSLSocketFactory(trustStore);
                sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    
                HttpParams params = new BasicHttpParams();
                HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
                HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    
                SchemeRegistry registry = new SchemeRegistry();
                registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
                registry.register(new Scheme("https", sf, 443));
    
                ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
    
                return new DefaultHttpClient(ccm, params);
            } catch (Exception ex)
            {
                return new DefaultHttpClient();
            }
    
        }
    
    
    }
    

    This class serves only to instance a Custom Socket Factory which allows to accept all valid and invalid server certificates. It is not advised to incurr in such practices on sensitive information services / transports, because accepting all certificates as valid allows a man-in-the-middle attack, as some other vulnerabilities.

    Hope this helps you.

    Best of luck.

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

Sidebar

Related Questions

I've been developing with kinect XBOX 360 for a while. Today, after connecting a
Error while connecting to external SQL Server IP using SQL Management Studio 2005 address
I would like to preserve a session while connecting to server using HttpGet and
After a while using the website, loading contents, etc.. this message shows Fill: SelectCommand.Connection
This is my thread: public void run() { Log.d(ConnectionThread,Starting Server Connection); try { while(isThereActivityRunning())
I am connecting to a server from an android device and querying the database
I'm connecting to a web server from my android application via HttpsUrlConnection or HttpUrlConnection
I am having a problem in connecting through WSS to my server. I followed
While trying to get a 2008 server to connect to a sql server, I
I'm working on a C# WebSocket server (currently supported by https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-17 ). The server

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.