Enviar una solicitud de obtención de http a un sitio web, ignorando la respuesta con c ++

I need to send a http get request using c++. My code as of now is:

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main ()
    ifstream llfile;


    char word[50];
    llfile >> word;
    cout << word;
    return 0;

The request would be something sent to:


preguntado el 03 de mayo de 12 a las 15:05

@MarcB : Seeing the URL example, I'd say he just wants to perform his request without considering the result and thus without parsing response. -

@MarcB Typo. Ignoring the response. -

@Tibor I haven't been able to find any ways of doing it and could not find any tutorials. That is why I came here. -

Does the target URL only work with GET requests? Otherwise you could use a HEAD request which does the same as a GET request, but does not return a response body. -

1 Respuestas

Possibly the easiest is to use libCurl.

Utilizando la 'easy interface' you just call curl_easy_init(), then curl_easy_setopt() to set the url, then curl_easy_perform() to make it do the getting. If you want the response (or progress, etc) then set the appropriate properties in setopt(). Once you're all done, call curl_easy_cleanup(). Job done!

The documentation is comprehensive - it's not just a simple lib to get http requests, but does practically every network protocol. Realise that the doc therefore looks pretty complicated, but it isn't really.

It might be an idea to go straight to the ejemplo code, the simple one looks like this:

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

int main(void)
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    res = curl_easy_perform(curl);

    /* always cleanup */ 
  return 0;

but you might want to check out the 'get a file in memory' sample or the 'replace fopen' one as well.

contestado el 03 de mayo de 12 a las 16:05

Thank you for you response. I am having trouble linking the Curl libraries to my compiler. I am using Code Blocks. - ash-breeze

Solved! I found another post on installing Curl. - ash-breeze

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.