Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all 4845 articles
Browse latest View live

New Post: Unable to build the program

$
0
0
Hi
I am trying to build the given program of "Http Client Tutorial" in Linux environment Ubuntu 14.04.
But i am getting many issues while building it.
May you provide all step by step guide to run in Ubuntu along with build commands.

include <cpprest/http_client.h>

include <cpprest/filestream.h>

using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams

int main(int argc, char* argv[])
{
auto fileStream = std::make_shared<ostream>();

// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
{
    *fileStream = outFile;

    // Create http_client to send the request.
    http_client client(U("http://www.bing.com/"));

    // Build request URI and start the request.
    uri_builder builder(U("/search"));
    builder.append_query(U("q"), U("Casablanca CodePlex"));
    return client.request(methods::GET, builder.to_string());
})

// Handle response headers arriving.
.then([=](http_response response)
{
    printf("Received response status code:%u\n", response.status_code());

    // Write response body into the file.
    return response.body().read_to_end(fileStream->streambuf());
})

// Close the file stream.
.then([=](size_t)
{
    return fileStream->close();
});

// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
    requestTask.wait();
}
catch (const std::exception &e)
{
    printf("Error exception:%s\n", e.what());
}

return 0;
}

New Post: http_client Get request method not working in cpprest of CASABLANCA SDK

$
0
0
I am trying to build a sample provided in Microsoft Casablanca in my Ubuntu environment. I am following the link: https://msdn.microsoft.com/en-us/library/jj950082.aspx

My code followed from above link:
#include <http_client.h>
#include <iostream>
#include <json.h>

using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace std;
// Retrieves a JSON value from an HTTP request.
pplx::task<void> RequestJSONValueAsync()
{
    // TODO: To successfully use this example, you must perform the request  
    // against a server that provides JSON data.  
    // This example fails because the returned Content-Type is text/html and not application/json.
    http_client client(U("http://www.fourthcoffee.com"));
    return client.request(methods::GET).then([](http_response response) -> pplx::task<json::value>
    {
        if(response.status_code() == status_codes::OK)
        {
            return response.extract_json();
        }

        // Handle error cases, for now return empty json value... 
        return pplx::task_from_result(json::value());
    })
        .then([](pplx::task<json::value> previousTask)
    {
        try
        {
            const json::value& v = previousTask.get();
            // Perform actions here to process the JSON value...
        }
        catch (const http_exception& e)
        {
            // Print error.
            wostringstream ss;
            ss << e.what() << endl;
            wcout << ss.str();
        }
    });

    /* Output:
    Content-Type must be application/json to extract (is: text/html)
    */
}


int main()
{
    // 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.

    wcout << U("Calling RequestJSONValueAsync..." )<< endl;
    RequestJSONValueAsync().wait();

}
Here i am trying to make GET request to url: http://www.fourthcoffee.com and get JSON data. While i compile and run it using the command in terminal:
sudo g++ -std=c++11 basic_http_client.cpp -o client -lboost_system -lcrypto -lssl -lcpprest
./client

I am facing an error:
Error: Failed to connect to any resolved endpoint.

What could be the possible issue here while making http GET request. Searched Google and SO with no possible solutions.

Created Unassigned: Create Unit test cased [440]

$
0
0
How to create unit test case using .net testing.
It is showing linking error to the library that uses cpprestsdk

Created Unassigned: Can't get value of large number [441]

$
0
0
I've got a json document that contains a big integer number that doesn't fit in a uint64.

I know the value doesn't fit in any built in C++ types. I was hoping to use something like boost::multiprecision::cpp_int which can be initialized with a number from a string.

But, web::json::value::as_string() throws if called on a value that isn't a string.

Is there a way to read a large integer? And if not, could it be a possible future fix/feature.

Thanks,
-Scott


New Post: Https Server Tutorial for Casablanca 2.6

$
0
0
Hello Cazador,
I look also for a http_listener working with json. do you know where I can find an example. you went through this same problem. And I can't get any sample anywhere that still work after the updates.

Thank you a lot!

New Post: Http_Listener with json. I can't access to the json data

$
0
0
Hello Everybody,

First of all I'm a beginner with C++ REST SDK. And I thank all of the contributors of this project for the great work you're doing!

So I'm lost in my implementation of the REST SDK (v2.8.0 NuGet) for an Http_Listener implemented in my C++ MFC app.

Actually I'm calling perfectly the handlers GET/POST/PUT/DELETE but I can only answer to the requests with strings :
message.reply(status_codes::OK, U("Hello, World! handle_delete"));
I use Postman to send POST requests with some JSON data as you can see:
Image on Imgur

But I tried a lot of times to find a way to work with the JSON data that I recieve. But nothing actually helped me to understand how to achieve it.

Do you have any Http_Listener sample working with json. I can't find any. Because I read these pages :
Using JSON
Old Msdn Doc
OLD EXAMPLE : Full-fledged client-server example with C++ REST SDK 1.1.0
and many other documentations on this website...

So I don't know what to use as functions or anything else to get the value from the json, make some actions in my MFC app and then send an answer in json.

So please give me any help to find how can I process recieved json data and how can I send some as answer.

Thank you a lot for your help.
Sincerely, Ahmed

New Post: invalid http_client when using ansi characters

$
0
0
I build a console application to download files with C++ REST SDK
I assign the http_client to a url as follows:
http_client client = utility::conversions::to_string_t(pwszUri);
with pwszUri of type const wchar_t*
All goes well as long as I don't use ansi in the pwszUri string. When I use, for instance,
https://en.wikipedia.org/wiki/Bajzë (note the last character: e with diaeresis) as a url the http_client becomes invalid. I can't find out why???
I'm using VS2013. Constructed a console project, with a wmain starting point.

New Post: invalid http_client when using ansi characters


New Post: Http_Listener with json. I can't access to the json data

$
0
0
Hello All.
I'm waiting for your answers. I tried to read more and more things about it but the most I read the most I get stuck. So this is a code snippet about where I'm blocked now:
void CMFCApplication1Dlg::handle_post(http_request Recieved_request)
{
    
    // /!\ here I want to get the json content of the recieved request but I can't... /!\ 
    pplx::task< json::value > req;

    req = Recieved_request.extract_json(false);
    //I need help here. How can I get the json values. This "req" is a task and don't contain json informations 
    // /!\ end of the work on the recieved POST request with json data.

    //I'm replying to the POST request with some json Data:
    json::value response;
    response[U("Success")] = json::value::string(L"Yes");
    response[U("Cmd")] = json::value::string(L"Erase_initial");
    response[U("Id")] = json::value::string(L"stv13");
    //end of the work on the response

    Recieved_request.reply(status_codes::OK, response);
};
So now I know how to send json data but I'm still blocked about how can I retrieve it in this Http_Listener.

All what I find is about clients and I can't implement it because the examples are too old and deprecated.

So please help me as much as you can and tell me how can I get the different json values from the http_request for my Listener.


Thank you all.
Sincerely, Ahmed

New Post: How to use in CPPRest SDK in Cross Platform Shared Library Project, Visual Studio 2015.

$
0
0
I need to to create Cross Platform Shared Library in Visual Studio 2015, it will serve as the common codebase for both iOS and android apps which i'll be building using this library. I've been able to successfully use CPPRest SDK in an empty project in Visual Studio via Nuget Package Manager but when i create a Shared Lib project and install CPPRest SDK via Nuget, it does not allow me to use it. (Doesn't let me include header, specifically).

I believe I'll have to build CPPRest SDK for iOS and Android separately and then place them in their respective directories in the project but I'm not sure how will it work exactly as building for iOS contains inclusion for native iOS libraries also, how will they be placed in Visual Studio.

Can anyone please help ? Has anyone done similar kind of thing ?

New Post: How to create empty json object correctly using web.json in cpp?

$
0
0
I want to create following json request:
{
  "Value1":{},
  "Value2":"some string value"
}
to achieve this I have tried following code in cpp:
json::value &refRequest
json::value jRequest = json::value();
refRequest[requestKey::Value1] = json::value(json::value::object()); //for creating empty object
refRequest[requestKey::Value2] = json::value::string("some string");
but it gives output as:
{
  "Value1":},
  "Value2":"some string value"
}
if you observe, instead of returning empty object as {} it gives the output as } and this results in to malformed request. I am not sure where exactly I am going wrong, any help will would be appreciated. Thanks

New Post: Using NTLM / Windows Authentication

$
0
0
Hello,
is there a way to use NTLM / Windows Authentication for the HTTP Client? Or is there a simple way to implement such a behaviour?

regards

Reviewed: C++ REST SDK 2.6.0 (Nov 10, 2016)

$
0
0
Rated 5 Stars (out of 5) - nothing , byebye

New Post: experimental::listener will become production ready soon???

$
0
0
Hello

I would like to use the http_listener to serve a webpage from a productional windows cpp legacy application.
  • need local communication without encryption
  • need to serve up to two requests at a time
A sample is working, but I am wondering about the experimental namespace.

May I rely on the functionality (with the limited use above) for a production environment?

When will the listener leave the experimental phase??

Thanks and best regards

Created Unassigned: Compilation internal error is coming while compiling "pplx::task_from_result" statement [442]

$
0
0
HI all,
I am using Visual Stuio 2010 and C++ Rest SDK 1.2.0. I am trying to call web service (GET). So while compiling the code am getting "An internal error has occurred in the compiler. 1> (compiler file f:\dd\vctools\compiler\utc\src\p2\ehexcept.c " error only when I add the state ment "pplx::task_from_result(web::json::value());"

Code:
return client.request(methods::GET).then([](http_response response)->pplx::task<web::json::value>{
if(response.status_code() == status_codes::OK)
{
return response.extract_json();
}
else
{
return pplx::task_from_result(web::json::value());
}
// Handle error cases, for now return empty json value...
//return pplx::task_from_result(json::value());
}).then([](pplx::task<web::json::value> previousTask){
try
{
const web::json::value& v = previousTask.get();
//DisplayJSONValue(v);
// Perform actions here to process the JSON value...
}
catch (const http_exception& e)
{
}

Commented Unassigned: http listener doesn't answer on vm machine [432]

$
0
0
Hi All,

I'm testing http_listener_test.cpp example, building on VS 2013 and using c++ rest v2.4.
My problem happens only on vmware machine where running the same demo application
I got no response from listener.
I don't unserstand why, the same application works fine on a real machine.

Any suggestion?
Thank you
Andrea
Comments: Have you found anyway to fix it? I have encountered the same problems.

Commented Unassigned: http listener doesn't answer on vm machine [432]

$
0
0
Hi All,

I'm testing http_listener_test.cpp example, building on VS 2013 and using c++ rest v2.4.
My problem happens only on vmware machine where running the same demo application
I got no response from listener.
I don't unserstand why, the same application works fine on a real machine.

Any suggestion?
Thank you
Andrea
Comments: Not really, I don't understand why but in this way the listener now it works: ``` listener.support(methods::GET, handle_get); listener.support(methods::POST, handle_post); listener.support(methods::PUT, handle_put); listener.support(methods::DEL, handle_del); try { listener .open() .then([&listener](){ DEBUG(DBG_DEBUG, "Started listener "); }) .wait(); while (true) { DEBUG(DBG_DEBUG, "Sleeping"); //wait an hour and verify log switch Sleep(3600000); DEBUG_CONF("outputfile", Logger::file_on, DBG_DEBUG, DBG_ERROR); }; } catch (exception const & e) { DEBUG(DBG_ERROR, e.what()); } ``` Good luck Andrea

Created Unassigned: Is there any requirements or prerequisite to use Casablanca? [443]

$
0
0
Hello.

I have already made an window desktop application with c++ rest sdk.

In order to publish, i did some testing my application on testing machines.

and.. i found a problem.

> on Windows 7 64bits SP1.
>
> http_client::request does not respond forever.


Other machines works correctly.


Is there any windows own prerequisite module to use it? (for example, dot net or ...)




New Post: Hanging requests...

$
0
0
http_client::request is never ended on Windows 7 64 bit SP1.

I am using some simple http requests like below.
http_client_config conf;
            conf.set_timeout(seconds(1));


            http_client client(m_url.c_str(), conf);
            http_request request(methods::POST);
            //request.set
            request.headers().set_content_type(U("application/json"));
            request.set_body(m_postData);

            auto deleted = m_deleted;
            pplx::task<void> task = client.request(request).then([deleted](http_response response) -> pplx::task<json::value>
            {
                if (*deleted)
                {
                    return pplx::task<json::value>();
                }


The request was never ended. (Even i set timeout.)

I have installed new OS on my test machine. and installed Redistribution package of VS 2015 in order to run my application. That is all what i did to test my app.

Of course the code are working correctly on my Developing Machine.

Is there any prerequisites of Casablanca? or did i miss something..?

I have got stuck in this problem and already checked whether the codes made any Exception or not.

No Exception. No Response forever.

Please give me a piece of advice.

Commented Unassigned: Is there any requirements or prerequisite to use Casablanca? [443]

$
0
0
Hello.

I have already made an window desktop application with c++ rest sdk.

In order to publish, i did some testing my application on testing machines.

and.. i found a problem.

> on Windows 7 64bits SP1.
>
> http_client::request does not respond forever.


Other machines works correctly.


Is there any windows own prerequisite module to use it? (for example, dot net or ...)




Comments: The reason of this. I used pplx::task as like a thread on my app. Casablanca did not respond unless the task finished. I am developing my app on Windows 10. In this case, It works correctly. However, on the some testing machines , including Windows 7 64bit SP1, are not working like my question. So, i changed the task to std::thread to resolve that.
Viewing all 4845 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>