I'd like to use Casablanca in RAD Studio, for a simple http get response.
I compiled in VS 2013, and then linked the lib. There was a OMF error, and used the tool coff2omf on the cpprest120_2_1.lib and after that it did not complain about the following dllimport's.
class __declspec(dllimport) http_client;
class __declspec(dllimport) filestream;
class __declspec(dllimport) producerconsumerstream;
class __declspec(dllimport) rawptrstream;
I can't seem to use it though. the http_client structure is not recognized, the namespace pplx is not recognized.
I know RAD Studio is not supported, for this particular task I am forced to use it. I saw a post for someone trying to use with RAD Studio, but they were only having VS compile problems.
Has anyone used Casablanca in RAD Studio? and if so could you please help with the steps needed to replicate the following VisualStudio code in RAD Studio.
Thank you,
This works for me in VisualStudio, and this is the only functions I need access to in RAD Studio. I replaced the real values with somewebsite etc..
using namespace concurrency::streams;
using namespace web::http;
using namespace web::http::client;
// Creates an HTTP request and prints the length of the response stream.
pplx::task<void> HTTPStreamingAsync()
{
int wmain()
{
I compiled in VS 2013, and then linked the lib. There was a OMF error, and used the tool coff2omf on the cpprest120_2_1.lib and after that it did not complain about the following dllimport's.
class __declspec(dllimport) http_client;
class __declspec(dllimport) filestream;
class __declspec(dllimport) producerconsumerstream;
class __declspec(dllimport) rawptrstream;
I can't seem to use it though. the http_client structure is not recognized, the namespace pplx is not recognized.
I know RAD Studio is not supported, for this particular task I am forced to use it. I saw a post for someone trying to use with RAD Studio, but they were only having VS compile problems.
Has anyone used Casablanca in RAD Studio? and if so could you please help with the steps needed to replicate the following VisualStudio code in RAD Studio.
Thank you,
This works for me in VisualStudio, and this is the only functions I need access to in RAD Studio. I replaced the real values with somewebsite etc..
include <cpprest/http_client.h>
include <cpprest/filestream.h>
include <iostream>
include <sstream>
include <cstdio>
include <cpprest/producerconsumerstream.h>
include <cpprest/rawptrstream.h>
include <codecvt>
using namespace concurrency;using namespace concurrency::streams;
using namespace web::http;
using namespace web::http::client;
// Creates an HTTP request and prints the length of the response stream.
pplx::task<void> HTTPStreamingAsync()
{
http_client client(L"http://www.somewebsite.com/somefunction.php?key=somevalue");
// Make the request and asynchronously process the response.
return client.request(methods::GET).then([](http_response response)
{
// Print the status code.
std::wostringstream ss;
ss << L"Server returned returned status code " << response.status_code() << L'.' << std::endl;
std::wcout << ss.str();
// std::wstring << ss.str();
if (response.status_code() != status_codes::OK)
{
// Handle error cases...
return pplx::task_from_result();
}
// Perform actions here reading from the response stream...
// In this example, we print the first 15 characters of the response to the console.
istream bodyStream = response.body();
container_buffer<std::string> inStringBuffer;
return bodyStream.read(inStringBuffer, 15).then([inStringBuffer](size_t bytesRead)
{
const std::string &text = inStringBuffer.collection();
// For demonstration, convert the response text to a wide-character string.
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf16conv;
std::wostringstream ss;
ss << utf16conv.from_bytes(text.c_str()) << std::endl;
std::wcout << ss.str();
});
});
/* Sample output:
Server returned returned status code 200.
Content length is 63803 bytes.
*/
}int wmain()
{
// This example uses the task::wait method to ensure that async operations complete before the app exits.
// In most apps, you typically don�t wait for async operations to complete.
std::wcout << L"Calling HTTPStreamingAsync..." << std::endl;
HTTPStreamingAsync().wait();
std::getchar();
}