Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> /* printf, sprintf */
- #include <stdlib.h> /* exit, atoi, malloc, free */
- #include <unistd.h> /* read, write, close */
- #include <string.h> /* memcpy, memset */
- #include <sys/socket.h> /* socket, connect */
- #include <netinet/in.h> /* struct sockaddr_in, struct sockaddr */
- #include <netdb.h> /* struct hostent, gethostbyname */
- #include <arpa/inet.h>
- #include "helpers.h"
- #include "requests.h"
- int main(int argc, char *argv[])
- {
- int i;
- char *message;
- char *response;
- int sockfd;
- /*
- * Ex 0: Get cs.curs.pub.ro
- *
- * Pas 1: Se deschide conexiunea (open_connection)
- * Pas 2: Se creaza mesajul de request (compute_get_request)
- * Pas 3: Se trimite la server mesajul (send_to_server)
- * Pas 4: Se primeste raspuns de la server (receive_from_server)
- * Pas 5: Se inchide conexiunea cu serverul (close_connection)
- */
- //TODO EX 0
- /*char ip[30];
- strcpy(ip, "141.85.241.51");
- sockfd = open_connection(ip, 80, AF_INET, SOCK_STREAM, 0);
- message = compute_get_request(ip, "/", NULL);
- send_to_server(sockfd, message);
- response = receive_from_server(sockfd);
- printf("%s", response);
- close_connection(sockfd);
- /*
- Ex 1: Get videos
- */
- // TODO EX 1
- /*
- strcpy(ip, "185.118.200.37");
- sockfd = open_connection(ip, 8081, AF_INET, SOCK_STREAM, 0);
- message = compute_get_request(ip, "/videos", NULL);
- send_to_server(sockfd, message);
- response = receive_from_server(sockfd);
- printf("%s", response);
- close_connection(sockfd);
- */
- /*
- EX 2.1: Add video
- */
- char ip[30];
- /*strcpy(ip, "185.118.200.37");
- sockfd = open_connection(ip, 8081, AF_INET, SOCK_STREAM, 0);
- message = compute_post_request(ip, "/videos", "id=11&name=Videoclip");
- printf("%s", message);
- send_to_server(sockfd, message);
- response = receive_from_server(sockfd);
- printf("%s", response);
- close_connection(sockfd);
- // TODO Ex 2.1
- sockfd = open_connection(ip, 8081, AF_INET, SOCK_STREAM, 0);
- message = compute_get_request(ip, "/videos", NULL);
- send_to_server(sockfd, message);
- response = receive_from_server(sockfd);
- printf("%s", response);
- close_connection(sockfd);
- /*
- Ex 2.2 Verificam noua colectie de videoclipuri
- */
- // TODO Ex 2.2
- strcpy(ip, "185.118.200.37");
- sockfd = open_connection(ip, 8081, AF_INET, SOCK_STREAM, 0);
- message = compute_post_request(ip, "/weather/login", "username=admin&password=p@ss");
- //printf("%s", message);
- send_to_server(sockfd, message);
- response = receive_from_server(sockfd);
- printf("%s", response);
- close_connection(sockfd);
- /*
- Ex 3 Autentificare
- */
- strcpy(ip, "185.118.200.37");
- sockfd = open_connection(ip, 8081, AF_INET, SOCK_STREAM, 0);
- message = compute_get_request(ip, "/weather/key", "isLogged=true");
- printf("%s", message);
- send_to_server(sockfd, message);
- response = receive_from_server(sockfd);
- printf("%s", response);
- close_connection(sockfd);
- strcpy(ip, "82.196.7.246");
- sockfd = open_connection(ip, 80, AF_INET, SOCK_STREAM, 0);
- message = compute_get_request(ip, "/data/2.5/weather", "q=bucharest&APPID=80f21fc11662726c0c3c8c5512d89b3a");
- printf("%s", message);
- send_to_server(sockfd, message);
- response = receive_from_server(sockfd);
- printf("%s", response);
- close_connection(sockfd);
- /*strcpy(ip, "185.118.200.37");
- sockfd = open_connection(ip, 8081, AF_INET, SOCK_STREAM, 0);
- message = compute_get_request(ip, "/weather/key", "username=admin&password=p@ss");
- //printf("%s", message);
- send_to_server(sockfd, message);
- response = receive_from_server(sockfd);
- printf("%s", response);
- close_connection(sockfd);
- // TODO Ex 3
- */
- free(message);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement