---
name: "http_fetch"
section: "3"
platform: "linux"
package: "libhttpfetcher-dev"
version: "1.0.1-3"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/http_fetch"
---

# http\_fetch(3)

Downloads a file via HTTP.

## NAME

**http\_fetch** - Downloads a file via HTTP.

## SYNOPSIS

**#include \<http\_fetcher.h\>**\

**int http\_fetch(const char \****url***, char \*\****fileBuf*);\

## DESCRIPTION

Download the file located at *url*.  Memory is allocated to hold the file, and is pointed to by *fileBuf*.

If you pass **NULL** for *fileBuf*, *url* will be requested but will not remain in memory (useful for simply registering a hit).

## RETURN VALUE

On success, **http\_fetch** returns the number of bytes of data downloaded (HTTP metadata not included).

On error, -1 is returned, and **http\_perror** can be used to print an informative error message.  **http\_strerror** can be used to get a pointer to the current error description message.

## SEE ALSO

[**http\_setUserAgent**(3)](/http_setUserAgent/3.md), [**http\_setReferer**(3)](/http_setReferer/3.md),\
 [**http\_setTimeout**(3)](/http_setTimeout/3.md), [**http\_parseFilename**(3)](/http_parseFilename/3.md), [**http\_perror**(3)](/http_perror/3.md), [**http\_strerror**(3)](/http_strerror/3.md)
