I'm trying to connect to a web server so I can scrape it but my program gives me the error: "Connection refused" coming from the connect function. heres the code:

```
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include <errno.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <regex.h>

#define MAXLINE 4096

int main() {
    char domain[255];
    char netAddr[255];
    char GETrqst[MAXLINE];
    char recvLine[MAXLINE];
    int rl;

    printf("webscraper\n\n");

    printf("enter the domain of the website you want to scrape (eg: google.com): ");
    scanf("%s", domain);

    //address struct
    //2 structs for the getaddrinfo function
    struct addrinfo getResult, *getResult2;
    memset(&getResult, 0, sizeof(getResult));
    getResult.ai_family = AF_INET;
    getResult.ai_socktype = SOCK_STREAM;

    int addrErr = getaddrinfo(domain, NULL, &getResult, &getResult2);

    if (addrErr != 0) {
        perror("getaddrinfo");
        exit(1);
    }

        //first half of ip
    if (inet_ntop(AF_INET, getResult2->ai_addr->sa_data, netAddr, 255)) {
        //second half of ip
        void *addr_in = &((struct sockaddr_in *) getResult2->ai_addr)->sin_addr;
        inet_ntop(AF_INET, addr_in, netAddr, 255);

        printf("ip for domain is: %s\n", netAddr);
    } else {
        perror("inet_ntop");
        exit(1);
    }

    struct sockaddr_in socket_address;
    //memset(&socket_address, 0, sizeof(socket_address));
    socket_address.sin_family = AF_INET;
    socket_address.sin_port = htons(80);

    int atonErr = inet_aton(getResult2->ai_addr->sa_data, &socket_address.sin_addr);

    if (atonErr != 0) {
        perror("inet_aton");
        exit(1);
    } else {
        printf("successfully converted string to struct\n");
    }

    freeaddrinfo(getResult2);

    printf("address struct setup\n");

    sleep(1);

    printf("setting up socket\n");

    int sock = socket(AF_INET, SOCK_STREAM, 0);

    sleep(1);

    printf("attempting connection to web server...\n");
    int connectStatus = connect(sock, (struct sockaddr *) &socket_address, sizeof(socket_address));

    if (connectStatus == -1) {
        perror("connect error");
        exit(1);
    } else {
        printf("connection success!\n");
    }

    sleep(1);
    //sets get command to get webpage. \r\n\r\n is at the end of every webpage url
    sprintf(GETrqst, "GET / HTTP/1.1\r\n\r\n");

    write(sock, GETrqst, sizeof(GETrqst));

    memset(recvLine, 0, MAXLINE);

    while ((rl = read(sock, recvLine, MAXLINE-1)) > 0 ) {
        printf("%s", recvLine);
    }

    exit(1);

    return 0;
} 

```

I've tried using memset() to reset the sockaddr\_in struct because that worked before but now it isn't working. I also checked if the ip was being saved and used properly and it is but none of those options worked. I'm very lost and i've been trying to fix this for about 2 hours. Any help would be appreciated!