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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:06:48+00:00 2026-05-24T03:06:48+00:00

I have to connect to some server with URL host/getdata?reqtype=generate&login=xxx&pass=xxx&dest=yyy using SSL. I’m using

  • 0

I have to connect to some server with URL host/getdata?reqtype=generate&login=xxx&pass=xxx&dest=yyy using SSL.

I’m using code snippet shown below but I can’t get any data from server.

CRYPTO_malloc_init();
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();

SSL_CTX* ctx = SSL_CTX_new(SSLv23_client_method());
SSL* ssl;
BIO* bio = BIO_new_ssl_connect(ctx);

char *host = "host:8888";
char *con_protocol = "";

const char *REQUEST_PROTO = "GET /getdata?reqtype=generate&login=xxx&pass=xxx&dest=yyy HTTP/1.1\nHost: %s\nAccept: */*\nConnection: keep-alive\n\n";

char *con_string = (char*)calloc((strlen(host)+strlen(con_protocol))+1, sizeof(char));

strcat(con_string, host);
strcat(con_string, con_protocol);

// Failure?
if (bio == NULL) {
   printf("Error creating BIO!\n");
        ERR_print_errors_fp(stderr);
   // We need to free up the SSL_CTX before we leave.
        SSL_CTX_free(ctx);
        return;
}
// Makes ssl point to bio's SSL object.
BIO_get_ssl(bio, &ssl);
// Set the SSL to automatically retry on failure.
SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
printf("connection string : %s\n", con_string);
BIO_set_conn_hostname(bio, con_string);

// Same as before, try to connect.
int y = BIO_do_connect(bio);
if (y <= 0) {
   printf("Failed to connect!\nError code : %d\n", y);
   BIO_free_all(bio);
   SSL_CTX_free(ctx);
   return;
}

// Now we need to do the SSL handshake, so we can communicate.
if (BIO_do_handshake(bio) <= 0) {
   printf("Failed to do SSL handshake!\n");
   BIO_free_all(bio);
   SSL_CTX_free(ctx);
   return;
}

// Create a buffer for grabbing information from the page.
char buf[1024];
memset(buf, 0, sizeof(buf));
// Create a buffer for the reqest we'll send to the server
char send[1024];
memset(send, 0, sizeof(send));


size_t total_size = strlen(REQUEST_PROTO)+strlen(host);
int t_size = (int)total_size+1;
    char *my_buf = malloc(t_size*sizeof(char));

    snprintf(my_buf, t_size, REQUEST_PROTO, host);

    printf("my_buf : %s\n", my_buf);

    BIO_puts(bio, my_buf);
    int temp = 0;
    int begin = 0;
    char *key_buff = (char *)calloc(32, sizeof(char));

    while (1) {
    int bytes_read = BIO_read(bio, buf, sizeof(buf) - 1);
        printf("bytes_read == %d\n", bytes_read);

        if (bytes_read == 0) {
            break;
        }
        else if (bytes_read < 0) {
            if (!BIO_should_retry(bio)) {
                printf("\nRead Failed!\n");
                BIO_free_all(bio);
                SSL_CTX_free(ctx);
                return;
            }
        }
        // We actually got some data, without errors!
        else {
            // Null-terminate our buffer, just in case
            buf[bytes_read] = 0;
            if ((bytes_read != 0) && (temp)) {
                for (begin; begin<(bytes_read+begin); begin++) {
                    key_buff[begin] = buf[begin];
                }
            }
            if (!temp) {
                temp = bytes_read;
            }

        }
    }

    BIO_free_all(bio);
    SSL_CTX_free(ctx);
    printf("key : %s\n\n", buf);

I’ve checked connection with CURL.
When using command
curl --insecure 'https://localhost:8888/getdata?reqtype=generate&login=xxx&pass=xxx&dest=yyy'
everything works, but when I remove ‘http’ from command, I get empty response as in the application. Unfortunately I can’t add ‘http’ in BIO_set_conn_hostname() function.
Some ideas what is wrong?

  • 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-24T03:06:49+00:00Added an answer on May 24, 2026 at 3:06 am

    Duskwuff is right, since you are apparently connecting via https, it would be much easier for you to use something higher level as cURL (you can use it programmatically using libcurl). Otherwise you’ll have to handle the HTTP part of the protocol all by yourself.

    If that’s acceptable for you, then I think the problem is that your BIO is not buffered, and that’s why you don’t get any data from the server using BIO_puts. See also this excellent turorial:

    Instead of using SSL_write() and SSL_read(), you can transmit data by calling BIO_puts() and BIO_gets(), and BIO_write() and BIO_read(), provided that a buffer BIO is created and set up as follows: …

    Using two BIOs (one for SSL, one for buffering) should solve your problem.

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

Sidebar

Related Questions

I have a postgreSQL Server with some databases. Every user can only connect to
I have an app which will connect to server and provide some basic connection
My Predicament: I have some things on my server that I want to connect
I have an IFrame app, and I would like to use some Connect features
I have some problem in my JDBC code. I am trying to connect through
I have to connect to a poorly implemented server that only understands Content-Type (capital-T)
I have an AIR application and would like to connect to an LDAP server
Need some guidance. I have java webstart app and I want it to connect
I have an issue that is occurring after my server reboots. I have some
I have recently installed svn server (Collabnet server) on some machine X (for example

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.