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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:18:07+00:00 2026-05-26T13:18:07+00:00

I am trying to authenticate to a server’s secure URL using java.net.urlconnection – based

  • 0

I am trying to authenticate to a server’s secure URL using java.net.urlconnection – based on the useful tutorial at Using java.net.URLConnection to fire and handle HTTP requests

The response will be as given below–

Return: A session id object: {'session_id': 'username:session_token'}
This session_id will be used for all methods which require authentication.

This response is JSON response, and I am thinking of using the Google GSON library (since my web app is on Google App Engine).

The code I have used so far (based on the tutorial to which I have given link above) is given below–

        String url = "https://api.wordstream.com/authentication/login";
        String charset = "UTF-8";
        String param1 = WORDSTREAM_API_USERNAME;
        String param2 = WORDSTREAM_API_PASSWORD;
        // ...
        String query = String.format("username=%s&password=%s", 
         URLEncoder.encode(param1, charset), 
         URLEncoder.encode(param2, charset));
        URLConnection connection = new URL(url + "?" + query).openConnection();
        connection.setRequestProperty("Accept-Charset", charset);
        InputStream response = connection.getInputStream();
        InputStream error = ((HttpURLConnection) connection).getErrorStream();
        //now checking HTTP Response status
        int status = ((HttpURLConnection) connection).getResponseCode();

How do I proceed further to obtain the JSON response and retrieve session ID from that response correctly?

Another question- I want to store the session ID in session data that can be accessed by javascript functions, because I plan to use javascript functions to make calls and obtain further data. Is this possible, and how to implement this?

  • 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-26T13:18:08+00:00Added an answer on May 26, 2026 at 1:18 pm

    Step 1- Create a subclass- declare it as static so that it can be utilised by the GSON library. This subclass should mimic the data contained in a single JSON Response- in our case only the session ID is stored in the response- hence this class contains just one string variable…

     static class LR { 
    
      public String response; 
    
      public LR() {
      // No args constructor for LR
       }
     }
    

    Now, use BUfferedReader and readline to read the entire response and store it in a string variable.

    InputStream response = connection.getInputStream();
            BufferedReader br = new BufferedReader(new     
    InputStreamReader(response));
    String str="", temp;
    while (null != ((temp = br.readLine())))
    {
        System.out.println (str);
        str=str + temp;             
    }       
    

    Finally, invoke ‘fromJSON(string, class)’ to obtain the value-

    Gson gson = new Gson();
    LR obj2 = gson.fromJson(str, LR.class);   
    return(" Session ID="+ obj2.response);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying go get WCF server and client mutually authenticate each other using SSL
I'm trying to authenticate with an XMPP server using SASL. /** * Send Authentication,
I'm trying to authenticate to a web server from an android class with the
I'm currently trying to authenticate via Active Directory Services using the PrincipalContext class. I
I am very new to NTLM/LDAP and trying to authenticate using NTML running on
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I'm trying to build a web service using Ruby on Rails. Users authenticate themselves
I am having trouble trying to connect to a secure OpenLDAP server which I
I'm trying to determine the most secure method for an ajax based login form
I'm trying to authenticate before using ajax to insert into a database $('#button').click(function ()

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.