I was looking for a HTTP header (preferably written in C) for my WiFi application to control a device. I am using a miniature USB WiFi module to connected to Raspberry Pi model B running Raspbian wheezy. Thank you.

  • 1
    Right now your question is very vague. More detail is needed for a better answer, such as what device you plan to control, what effort you have put forth already, etc. – syb0rg Nov 20 '13 at 22:56


HTTP is the serialization protocol used with the world wide web. An HTTP header is used to communicate between client and server and to wrap content payloads sent from one to the other.

HTTP is a plain text protocol. There are two fundamental sorts of headers, requests (client -> server) and responses (server -> client). A typical request header might be:

GET /somepage.html HTTP/1.1
Host: localhost
Connection: keep-alive
User-Agent: Mozilla/5.0

In this case, the request is just the header, there is no payload. The response might be:

HTTP/1.1 404 Not found
Content-Length: 151
Cache-Control: max-age=0
Content-Type: text/html; charset=UTF-8

This time, there's a payload attached (a 151 byte html page in UTF-8; here we can infer it's a "Sorry, the resource you requested cannot be found" type thing).

You could use C to produce either of those, but there's no such thing as a header in C. They're plain text.

Perhaps what you are looking for is an HTTP server with a C interface. Most general purpose servers have a CGI interface, which is based on executing a sub-process with the HTTP request processed into environment variables (and any payload fed via stdin); the response, including a partial header, is written to stdout.

So that can be in any language you like. There are other ways to produce web pages dynamically. Apache (aka. httpd) has a C API, although this might be overkill in this context. Other web servers available on the pi which may also have a C interface are nginx, lighthttpd, and yaws.

| improve this answer | |

You would have to use sockets in order to do that, or you could try using libcurl instead of sockets:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
  CURL *curl;
  CURLcode res;
  struct curl_slist *headers = NULL;

  curl = curl_easy_init();
    headers = curl_slist_append(headers, "Host: www.google.com");
    headers = curl_slist_append(headers, "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0");
    headers = curl_slist_append(headers, "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    headers = curl_slist_append(headers, "Accept-Language: en-us,en;q=0.5");
    /* Add more headers here */
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    res = curl_easy_perform(curl);

    /* Always cleanup */ 
  return 0;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.