Socket C ansi header Post

0

Hello, I have a socket in C ansi without using additional libraries normally working with http requests. When requesting on a new server does not get any response, using the lib curl, it results 100-continue and does the process normally.

How, through the socket without curl I can receive the data with a 100-continue response?

Thank you

    
asked by anonymous 15.07.2016 / 17:54

1 answer

0
Assuming you want to access a local server, Apache is active and if you make a connection through Socket , after connecting to the server, a Header (Header).

main:

const int PORT = 8080;
int _sock;
int res;
char buffer[] = "GET / HTTP/1.1"
"Host: localhost:8080"
"User-Agent: WebBrowser (<GUI>; <OS>; rv:<version>)"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9"
"Accept-Language: pt-BR"
"Connection: keep-alive";

struct sockaddr_in serv;
struct hostent *server;

_sock = socket(AF_INET, SOCK_STREAM, TCP);
server = gethostbyname("127.0.0.1");
serv.sin_family = AF_INET;
serv.sin_port = htons(PORT);
bcopy((char *) server->h_addr,
                        (char *) &serv.sin_addr.s_addr,
                        server->h_length);
int len = sizeof(serv);
res = connect(_sock, (struct sockaddr *) &serv, len);
write(_sock,buffer, strlen(buffer))

while(1)
    if(read(_sock, &c, 1) != 1)
        break;
    else
        write(stdout, &c, 1);

close(_sock);

WebServers takes information from the user who accesses the server through this header. So you do not have to use curl to make the request to the server.

    
19.07.2016 / 06:25