-1

I am looking for some tips how to read strings from a remote server over HTTP and save it into a string. Currently, I aim towards reading the first character.

@edit: what I have already done:

I thought that curl might be the right tool to achieve that.

compilation:

1>------ Rebuild All started: Project: cURL, Configuration: Debug Win32 ------
1>  stdafx.cpp
1>  cURL.cpp
1>  cURL.vcxproj -> C:\Users\Lukasz\Documents\Visual Studio 2010\Projects\cURL\Debug\cURL.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

but after debug:

The procedure entry point sasl_errdetail could not be located in the dynamic link library libsasl.dll

my main file.cpp:

// cURL.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


#include <curl.h>
#include <cstdio>
#include <string>


std::string buffer;

size_t curl_write( void *ptr, size_t size, size_t nmemb, void *stream)
{
buffer.append((char*)ptr, size*nmemb);
return size*nmemb;
}

int main(int argc, char **argv)
{
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://google.com"); 
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
fwrite( buffer.c_str(), buffer.length(), sizeof(char), stdout);
return 0;
}
Luke
  • 2,350
  • 6
  • 26
  • 41

3 Answers3

1

I had same problem!!

downloaded libsasl.dll from dlldll.com and getting same error. I assumed they have old version of dll so I downloaded newer version and it worked like a charm.

I got never version from http://theetrain.ca/tech/files/libsasl.dll

Pavel
  • 26
  • 1
0
  1. Open the file.
  2. Use the fgetc or istream::read functions.
  3. Convert character to proper bool value.
  4. Close the file.

HTML files can be read like text files.

Parsing an HTML file is another issue.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
0

Simply to receive html in a server/client setup requires that you connect to a socket and handle the messages that come over the socket.

Here is a well done example that introduces Sockets on Windows:

Programming Windows TCP Sockets in C++ for the Beginner

If you want to completely avoid learning sockets and getting really good control of what is going on, you can use just a URL Downloader of sorts:

Download a URL in C

But using URLOpenStream will probably give you the fastest results, if you need speed over anything else.

So after you have a socket that receives the text of html, then you can parse the html and convert what you find into the appropriate variable.

Community
  • 1
  • 1
phyatt
  • 18,472
  • 5
  • 61
  • 80