1

Could anyone share a sample program to see how to use httplib_connect_client() :libhttp library to connect to my host server?

struct lh_con_t *httplib_connect_client( struct lh_ctx_t *ctx, const char *host, int port, int use_ssl )

Please provide a sample program

Adding the code i'm trying

#include <stdio.h>
#include <string.h>
#include "libhttp.h"
int main()
{
    int ret = 0;

    
    struct lh_con_t *newconn = NULL;
    struct lh_ctx_t *context = NULL;
    newconn = httplib_connect_client(context,"www.example.com", 8080, 1);
    if (newconn == NULL) {
        printf("Error: ");
        return 1;
    }


    return ret;
}

with this code i'm not able to establish a connection to the remote server.

LIJIN T V
  • 81
  • 8
  • 1
    "Could anyone share a sample program..." No we can't. But if you create a [mcve] of your own attempt, and show it to us together with a description of the problems you have with it we might be able to help you solve them. Also please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Oct 19 '20 at 06:56
  • 1
    The function is explained here. https://www.libhttp.org/httplib_connect_client/ to call it seems fairly trivial `http_libconnection* connection = httplib_connect_client("google.com",443,1,NULL,0);` Haven't tested but that should be it. – Irelia Oct 19 '20 at 07:03
  • @Someprogrammerdude i have added the code as you said – LIJIN T V Oct 19 '20 at 10:49
  • @Nina the API document is having different set of parameters than the actual function declaration in the source code : `struct lh_con_t *httplib_connect_client( struct lh_ctx_t *ctx, const char *host, int port, int use_ssl )` – LIJIN T V Oct 19 '20 at 12:03
  • Try making these changes to your code `struct lh_ctx_t context = {0};` then `newconn = httplib_connect_client(&context,"www.example.com", 8080, 1);` – Irelia Oct 19 '20 at 14:23

0 Answers0