PMHTTPNEWCLIENT(3)
π PMHTTPNEWCLIENT β like, the whole HTTP client thing
okay bestie, welcome to PMHTTPNEWCLIENT(3), a page from the Library Functions Manual β¨. It's the group chat of three little functions β pmhttpNewClient, pmhttpFreeClient and pmhttpClientFetch β and together they're the simple HTTP client interfaces πΈ. Lowkey iconic.
β¨ C SYNOPSIS β¨
first things first, you gotta pull in the headers, no cap:
#include <pcp/pmapi.h>
#include <pcp/pmhttp.h>
struct http_client *pmhttpNewClient(void);
void pmhttpFreeClient(struct http_client *client);
int pmhttpClientFetch(struct http_client *client, const char *url,
char *bodybuf, size_t bodylen, char *typebuf,
size_t typelen);
and when you link, you link it like this, periodt:
cc ... -lpcp_web
π DESCRIPTION π
okay so. pmhttpNewClient allocates and initializes an opaque HTTP client for you β it comes out ready to make requests from a server. That's it, that's the whole job. She's fresh, she's ready, she's got main character energy π
Now the URL request interface, pmhttpClientFetch, is the one that actually does the talking: it issues an HTTP GET request to the server you named in the url you handed it π¨. The body of the response comes back to you in the caller-supplied bodybuf buffer, which is bodylen bytes long. You can also pass an optional typebuf buffer of typelen bytes β and if it's non-NULL it'll hold the value of the content-type header the server sent back π.
The url parameter is an RFC1630 format URL. Usually that means it's prefixed with "http://", but listen β these interfaces also support Unix domain sockets π¦. Those get prefixed with "unix://" instead, followed by the full filesystem path to the Unix domain socket you want. iykyk.
And when you're done and you need to free up the resources tied to an HTTP client β including closing any persistent server connection that got established earlier β that's pmhttpFreeClient's moment π
. She cleans up. She closes the connection. She says bye π«Ά.
π₯ DIAGNOSTICS π₯
pmhttpNewClient will hand you back NULL on failure, and ngl there's literally only one way that happens: when allocation of memory is just not possible π.
pmhttpClientFetch will return the number of bytes placed into the bodybuf buffer, or else a negated error code telling you the nature of the failure. So if you see a negative number, that's your vibe check failing, bestie π.
π SEE ALSO π
go read these, they're all part of the lore:
and that's the whole page, fr fr β brought to you by Performance Co-Pilot (that's the PCP girlies π) and yeah, this is the PMHTTPNEWCLIENT(3) page, mwah π
π¦ where this page comes from
- arch rolling: pcp 7.2.2-2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0
- centos-stream 10: pcp-doc 7.1.5-6.el10 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.0.1-1.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.2.1-1.fc43
- fedora 43: pcp-doc 7.2.2-1.fc43
- fedora 43: pcp-doc 7.2.2-2.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.1.0-6.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.2.1-1.fc44
- fedora 44: pcp-doc 7.2.2-1.fc44
- fedora 44: pcp-doc 7.2.2-2.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- ubuntu resolute: libpcp-web1-dev 7.1.1-1
- ubuntu stonking: libpcp-web1-dev 7.2.1-2build1
- Copyright (c) 2016 Red Hat
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms