Нужно было использую libcurl отправить и получить ответ вебсервера. С опыта использования данной библиотеки под пхп я хотел написать подобную реализацию, но опции CURLOPT_RETURNTRANSFER , в сишной версии не оказалось. Как оказалось интерфефс получения ответа и записи в с++ выглядит вообще иначе: как опцию мы должны задать калбек функцию для чтения данных с сокета, и буфер. На ответ данного вопроса мною было потрачено n-нное время и я решил опубликовать пример сюда в блог.

  1. #include <stdio.h>
  2. #include <curl/curl.h>
  3. #include <curl/types.h>
  4. #include <curl/easy.h>
  5. struct MemoryStruct {
  6. char *memory;
  7. size_t size;
  8. };
  9. void *myrealloc(void *ptr, size_t size)
  10. {
  11. /* There might be a realloc() out there that doesn’t like reallocing
  12. NULL pointers, so we take care of it here */
  13. if(ptr)
  14. return realloc(ptr, size);
  15. else
  16. return malloc(size);
  17. }
  18. size_t
  19. WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
  20. {
  21. size_t realsize = size * nmemb;
  22. struct MemoryStruct *mem = (struct MemoryStruct *)data;
  23. mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
  24. if (mem->memory) {
  25. memcpy(&(mem->memory[mem->size]), ptr, realsize);
  26. mem->size += realsize;
  27. mem->memory[mem->size] = 0;
  28. }
  29. return realsize;
  30. }
  31. int main(int argc, char **argv)
  32. {
  33. CURL *curl_handle;
  34. struct MemoryStruct chunk;
  35. chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
  36. chunk.size = 0; /* no data at this point */
  37. curl_global_init(CURL_GLOBAL_ALL);
  38. /* init the curl session */
  39. curl_handle = curl_easy_init();
  40. /* specify URL to get */
  41. curl_easy_setopt(curl_handle, CURLOPT_URL, «http://cool.haxx.se/»);
  42. /* send all data to this function  */
  43. curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
  44. /* we pass our ‘chunk’ struct to the callback function */
  45. curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
  46. /* some servers don’t like requests that are made without a user-agent
  47. field, so we provide one */
  48. curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, «libcurl-agent/1.0″);
  49. /* get it! */
  50. curl_easy_perform(curl_handle);
  51. /* cleanup curl stuff */
  52. curl_easy_cleanup(curl_handle);
  53. /*
  54. * Now, our chunk.memory points to a memory block that is chunk.size
  55. * bytes big and contains the remote file.
  56. *
  57. * Do something nice with it!
  58. *
  59. * You should be aware of the fact that at this point we might have an
  60. * allocated data block, and nothing has yet deallocated that data. So when
  61. * you’re done with it, you should free() it as a nice application.
  62. */
  63. return 0;
  64. }

для норм просмотра: http://pastebin.com/f23c28e26