#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <yuarel.h>
int main(int argc, char* argv[]) {
char* url = malloc(argc <= 1 ? 28 : strlen(argv[argc - 1] + 1));
strcpy(url, argc <= 1 ? "http://postman-echo.com/get" : argv[argc - 1]);
printf("Requesting %s\n", url);
struct yuarel url_info;
if (yuarel_parse(&url_info, url) == -1) {
printf("Failed parsing URL\n");
exit(1);
}
winyl host =
winyl_open(url_info.host, url_info.port == 0 ? 80 : url_info.port);
printf(
"Error code %d\n", host.
error);
exit(1);
}
printf("\n");
printf(
"%s\n", res.
body);
free(url);
exit(0);
}
Contains the winyl_request function and related.
void winyl_response_close(winyl_response *response)
Frees memory used up by response.
#define WINYL_REQUEST_SLASH
Adds a slash to the beginning of the path passed. Useful for yuarel.
Definition request.h:46
winyl_response winyl_request(winyl *host, char *path, int flags)
Performs a HTTP request.
Represents a HTTP response.
Definition request.h:13
char * body
Response body.
Definition request.h:34
Represents a HTTP host.
Definition winyl.h:27
int error
Contains the error code after any winyl call.
Definition winyl.h:29
Contains the winyl_open function and related.
void winyl_close(winyl *host)
Frees memory used up by host.
winyl winyl_open(char *hostname, int port)
Opens an HTTP host with the specified port.