Quantcast
Viewing all 4845 articles
Browse latest View live

New Post: monitoring page

Hi opreanstefan,

Ok based on what you've describe then it sounds like you need to create an http_listener for processing requests querying about the status of your other application. Then in your http_listener you need to have a way to determine if your application is up and running and respond to the HTTP requests appropriately.

Don't take a look at or use http_linux_server. It shouldn't be part of the reference documentation and is technically an implementation detail that needs to be under a details namespace. The http_listener is the correct class.

Steve

Commented Feature: Windows - support for utf-8, single byte strings [239]

On Windows string_t is a 2 byte character, assumed UTF-16 string in the C++ Rest SDK. For some data critical areas we could make API overloads that work with std::string or return std::string.

This has come up numerous times from customers, internal and external.

Steve
Comments: It would be awesome to give a choice between UTF8 and UTF16. My team wants to keep all our data in UTF8 and we would like to use the JSON parsing component of the C++ Rest SDK. We saw in the source code that there is an #ifdef _WIN32 that makes all strings wstrings. That forces us to convert from UTF-16 to UTF8, then parse the JSON, then extract some string data from JSON, then convert that back to UTF-8. We would love to avoid all that needless conversion (the files are UTF-8 on disk)

New Post: producer_consumer_buffer, large file and "multipart/form-data"

hi,

Struggling to make it right. I found nice explanation how to implement simple scenario when file is loaded into memory upfront https://casablanca.codeplex.com/discussions/568637

but is there way to upload file incrementally using producer_consumer_buffer (critical for big files when loading all these MBs and GBs makes not sense)? Like some event to get new chunk of data.

Thank you!

New Post: Trying to Replicate a Post make from the Chrome REST Console to Prosper.com using the REST SDK

Hello,

I am trying to create a program to interface with the API of the peer-to-peer lending site, Prosper.com. I am able to successfully post a loan request from the REST Console of Chrome, but I am unable to duplicate this request within my C++ program and I'm hoping someone can help identify my mistake(s).

Here are the parameters I entered into the REST Console:

Request URI: https://api.prosper.com/api/Invest/
Request Method: POST
Request Timeout: 60 seconds
Content-Type: application/x-www-form-urlencoded
Request Parameters:
amount, 25.00
listingId, 2430877
Authorization Header: Basic EncodedStringHere

When I clicked the "Send" button, I received a response that the request was a success and the loan was made. Here is the request header reported by the REST Console:

Content-Type: application/x-www-form-urlencoded
Authorization: Basic EncodedStringHere
Accept: /
Connection: keep-alive
Origin: chrome-extension: //rest-console-id
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36

and here is the request body:

Request Url: https://api.prosper.com/api/Invest/
Request Method: POST
Status Code: 200
Params: {
"amount": "25.00",
"listingId": "2430877"
}

So I figured that if I could just duplicate this header and body from within my C++ program, that it would also work, but I get a return code of 400. Here is my code:
http_client client(U("https://api.prosper.com"));
http_request req(methods::POST);
req.set_request_uri(U("api/Invest"));
req.headers().add(header_names::authorization, U("Basic EncodedStringHere"));
req.headers().add(header_names::content_type, U("application/x-www-form-urlencoded"));
req.headers().add(header_names::connection, U("keep-alive"));
req.headers().add(header_names::accept, U("*/*"));
wchar_t parmString[] = L"Params: {\n   \"listingId\": \"2430877\",\n   \"amount\": \"25.00\"\n}";
wchar_t bodyString[1000];
swprintf(bodyString,L"Request Url: https://api.prosper.com/api/Invest/\nRequest Method: POST\nStatus Code: 200\n%s",parmString);
req.set_body(bodyString);
http_response response = client.request(req).get();
if(response.status_code() == status_codes::OK)
{
  auto body = response.extract_string();    
  AfxMessageBox(CString(body.get().c_str()));
}
else {
    CString errorString;
    errorString.Format("Error Code: %d", response.status_code());
    AfxMessageBox(errorString);
    AfxMessageBox(CString(bodyString));
} 
The last line displays the body, which I have confirmed is identical to the body reported by the REST Console.

Any help would be greatly appreciated.

Gary

New Post: Reference to PropertyPageSchema default-propertiesui.xml in cpprestsdk.targets / nuget package

Hi folks,

I'm having some issues with a VS2013 project rebuilding unnecessarily.

I think I might have tracked it back to our imported cpprestsdk.targets where we have -
<ItemGroup>
    <PropertyPageSchema Include="$(MSBuildThisFileDirectory)default-propertiesui.xml" />
  </ItemGroup>
I'm quite new to nuget. Any idea if the file is supposed to be present or perhaps that line is erroneous? It's absence is generating subtle errors in the visual studio dependency checks.

Ed

New Post: producer_consumer_buffer, large file and "multipart/form-data"

Created Unassigned: Web api server memory leak [348]

Hi,
I am using casablanca from NUGet (<package id="cpprestsdk" version="2.4.0.1" targetFramework="Native" />). VS2013. I have a cpu and memory leak on practical empty project and one project only returning some demo JSON values. I tested it with perfmon so I do not have any leak report. Can anybody help? This is simplified version:

void request_handler(http_request req)
{
http_response response(web::http::status_codes::OK);
req.reply(response);
}
int main()
{
http_listener listener(U("http://localhost:9888/services/"));
listener.open().wait();

listener.support(&request_handler);

while (true) {
this_thread::sleep_for(chrono::milliseconds(2000));
}

...
}

Edited Unassigned: Web api server memory leak [348]

Hi,
I am using casablanca from NUGet (<package id="cpprestsdk" version="2.4.0.1" targetFramework="Native" />). VS2013. I have a cpu and memory leak on practical empty project (few hours testing) and one project only returning some demo JSON values (over weekend). I tested it with perfmon so I do not have any leak report. Can anybody help? This is simplified version:

void request_handler(http_request req)
{
http_response response(web::http::status_codes::OK);
req.reply(response);
}
int main()
{
http_listener listener(U("http://localhost:9888/services/"));
listener.open().wait();

listener.support(&request_handler);

while (true) {
this_thread::sleep_for(chrono::milliseconds(2000));
}

...
}

Edited Unassigned: Web api server memory leak [348]

Hi,
I am using casablanca from NUGet (<package id="cpprestsdk" version="2.4.0.1" targetFramework="Native" />). VS2013. I have a cpu and memory leak on practical empty project (few hours testing) and one project only returning some demo JSON values (over weekend). I tested it with perfmon so I do not have any leak report. Perfmon screenshot in attachment. Can anybody help? This is simplified version:

void request_handler(http_request req)
{
http_response response(web::http::status_codes::OK);
req.reply(response);
}
int main()
{
http_listener listener(U("http://localhost:9888/services/"));
listener.open().wait();

listener.support(&request_handler);

while (true) {
this_thread::sleep_for(chrono::milliseconds(2000));
}

...
}

Edited Unassigned: Web api server memory leak [348]

Hi,
I am using casablanca from NUGet (<package id="cpprestsdk" version="2.4.0.1" targetFramework="Native" />). VS2013. I have a cpu and memory leak on practical empty project (few hours testing) and one project only returning some demo JSON values (over weekend). I tested it with perfmon so I do not have any leak report. Perfmon screenshot in attachment. Can anybody help? This is simplified version:

```
void request_handler(http_request req)
{
http_response response(web::http::status_codes::OK);
req.reply(response);
}
int main()
{
http_listener listener(U("http://localhost:9888/services/"));
listener.open().wait();

listener.support(&request_handler);

while (true) {
this_thread::sleep_for(chrono::milliseconds(2000));
}

...
}
```

Edited Unassigned: Web api server memory leak [348]

Hi,
I am using casablanca from NUGet (<package id="cpprestsdk" version="2.4.0.1" targetFramework="Native" />). VS2013. I have a cpu and memory leak on practical empty project (few hours testing) and one project only returning some demo JSON values (over weekend). Both test had get requests 10 times per second. Demo data was a list of 20 items with 3 strings. I tested it with perfmon so I do not have any leak report. Perfmon screenshot in attachment. Can anybody help? This is simplified version:

```
void request_handler(http_request req)
{
http_response response(web::http::status_codes::OK);
req.reply(response);
}
int main()
{
http_listener listener(U("http://localhost:9888/services/"));
listener.open().wait();

listener.support(&request_handler);

while (true) {
this_thread::sleep_for(chrono::milliseconds(2000));
}

...
}
```

Edited Unassigned: Casablanca memory leak [348]

Hi,
I am using casablanca from NUGet (<package id="cpprestsdk" version="2.4.0.1" targetFramework="Native" />). VS2013. I have a cpu and memory leak on practical empty project (few hours testing) and one project only returning some demo JSON values (over weekend). Both test had get requests 10 times per second. Demo data was a list of 20 items with 3 strings. I tested it with perfmon so I do not have any leak report. Perfmon screenshot in attachment. Can anybody help? This is simplified version:

```
void request_handler(http_request req)
{
http_response response(web::http::status_codes::OK);
req.reply(response);
}
int main()
{
http_listener listener(U("http://localhost:9888/services/"));
listener.open().wait();

listener.support(&request_handler);

while (true) {
this_thread::sleep_for(chrono::milliseconds(2000));
}

...
}
```

Edited Unassigned: Casablanca server memory leak [348]

Hi,
I am using casablanca from NUGet (<package id="cpprestsdk" version="2.4.0.1" targetFramework="Native" />). VS2013. I have a cpu and memory leak on practical empty project (few hours testing) and one project only returning some demo JSON values (over weekend). Both test had get requests 10 times per second. Demo data was a list of 20 items with 3 strings. I tested it with perfmon so I do not have any leak report. Perfmon screenshot in attachment. Can anybody help? This is simplified version:

```
void request_handler(http_request req)
{
http_response response(web::http::status_codes::OK);
req.reply(response);
}
int main()
{
http_listener listener(U("http://localhost:9888/services/"));
listener.open().wait();

listener.support(&request_handler);

while (true) {
this_thread::sleep_for(chrono::milliseconds(2000));
}

...
}
```

New Post: Reference to PropertyPageSchema default-propertiesui.xml in cpprestsdk.targets / nuget package

Hi Ed,

Yes, this does look like an erroneous msbuild item. Do your rebuilds get better if you remove it?

roschuma

New Post: producer_consumer_buffer, large file and "multipart/form-data"

Hi denveloper,

There are a couple of different options. You could write to the producer_consumer_buffer in chunks. If you data is coming from a file the best thing probably would be to use a file buffer/file_stream. The steps basically consist of calling the factory function on the file_stream class, file_stream<uint8_t>::open_istream(filename). This function is asynchronous and returns a task of an input stream that you can then pass as the body of and http_request using the http_request::set_body(stream) method and set the Content-Type. Then what will happen is the stream will be read from in chunks, 64KB by default but configurable with http_client_config::set_chunksize, and sent out. The BingRequest sample uses a file buffer to save the HTTP response, instead for your case instead you will want to use the file buffer as the request body.

Steve

Commented Unassigned: Casablanca server memory leak [348]

Hi,
I am using casablanca from NUGet (<package id="cpprestsdk" version="2.4.0.1" targetFramework="Native" />). VS2013. I have a cpu and memory leak on practical empty project (few hours testing) and one project only returning some demo JSON values (over weekend). Both test had get requests 10 times per second. Demo data was a list of 20 items with 3 strings. I tested it with perfmon so I do not have any leak report. Perfmon screenshot in attachment. Can anybody help? This is simplified version:

```
void request_handler(http_request req)
{
http_response response(web::http::status_codes::OK);
req.reply(response);
}
int main()
{
http_listener listener(U("http://localhost:9888/services/"));
listener.open().wait();

listener.support(&request_handler);

while (true) {
this_thread::sleep_for(chrono::milliseconds(2000));
}

...
}
```
Comments: Hi krajna, I think this is an already solved known issue. Basically the problem is with the task scheduling in the PPL library that we use. With Visual Studio 2013 it schedules work on the Concurrency Runtime and over time this can run into issues with too many threads being creating both eating up memory and the CPU. The fix is to have work scheduled on the Windows Threadpool which handles better the management of threads. For more details on the problem take a look at this previous [issue](https://casablanca.codeplex.com/workitem/341). It has 2 ways to fix, one is upgrading to Visual Studio 2015, the other is to recompile the C++ REST SDK with the macro CPPREST_FORCE_PPLX. Steve

New Post: Trying to Replicate a Post make from the Chrome REST Console to Prosper.com using the REST SDK

Hi Gary,

One issue that I can spot is you aren't actually setting any of the URI query parameters. The variable parmString isn't used to set any information on the outgoing http_request object. According to the documentation for the Prosper invest API it looks like you need to pass them as query parameters. I recommend using our uri_builder, it should make it easy to put everything together.

Steve

Commented Unassigned: nullptr defined as NULL on g++ [340]

Using g++ with C++ Rest SDK redefines nullptr as NULL even if nullptr is available.

In file include/cpprest/details/SafeInt3.hpp the following code is used to check if nullptr is available:

```
#if defined nullptr_t
#define NEEDS_NULLPTR_DEFINED 0
#else
#define NEEDS_NULLPTR_DEFINED 1
#endif
...
#if NEEDS_NULLPTR_DEFINED
#define nullptr NULL
#endif
```
However this is not a valid check (nullptr_t is a type so #if defined nullptr_t always evaluate to false leading to NEEDS_NULLPTR_DEFINED always beeing defined to 1).

Trying to change
```
#if defined nullptr_t
```
to
```
#if __cplusplus >= 201103L
```
which seems to be a more valid check breaks compilation (c.f. build_output.txt) of C++ REST SDK on my machine (using g++ 4.9.2 and boost 1.57.0).
Comments: Fixed in the development branch by the following pull request: https://casablanca.codeplex.com/SourceControl/network/forks/simonlep/cpprest/contribution/8067#!/tab/comments Will be in the 2.5.0 release. Steve

Closed Unassigned: nullptr defined as NULL on g++ [340]

Using g++ with C++ Rest SDK redefines nullptr as NULL even if nullptr is available.

In file include/cpprest/details/SafeInt3.hpp the following code is used to check if nullptr is available:

```
#if defined nullptr_t
#define NEEDS_NULLPTR_DEFINED 0
#else
#define NEEDS_NULLPTR_DEFINED 1
#endif
...
#if NEEDS_NULLPTR_DEFINED
#define nullptr NULL
#endif
```
However this is not a valid check (nullptr_t is a type so #if defined nullptr_t always evaluate to false leading to NEEDS_NULLPTR_DEFINED always beeing defined to 1).

Trying to change
```
#if defined nullptr_t
```
to
```
#if __cplusplus >= 201103L
```
which seems to be a more valid check breaks compilation (c.f. build_output.txt) of C++ REST SDK on my machine (using g++ 4.9.2 and boost 1.57.0).

Updated Release: C++ Rest SDK 2.5.0

Android
  • Fixed issue in CMakeLists.txt where parenthesis were incorrectly used instead of brackets.
  • Fixed issue in CMakeLists.txt where pplxlinux.cpp source file was missing.
  • Added Android TestRunner packing androidproj to build.

Windows
  • Fixed several code analysis warnings.
  • Updating NuGet package for missing OpenSSL license, also patched 2.4.0's NuGet package.
  • Fixed not working on XP issue because of crypto API. #331, #334
  • Fixed several functions missing an explicit calling convention. This caused problems if you changed the calling convention from the cdecl.
  • Added support for Windows on Devices/Galileo. #217
  • Added option to force using PPLX on Windows Threadpool instead of PPL on the Concurrency Runtime. Library can be rebuilt using CPPREST_FORCE_PPLX macro.
  • Updated all binaries to use whole program optimizations, slightly decreasing binary size and small potential performance improvements.
  • Merged pull request adding support for CMake for Windows desktop.

OSX
  • Merged a pull request to work around a FindOpenSSL.cmake issue, enabling it to find Homebrew's copy.
  • Added support for iOS 64bit simulator. #196

websocket_client
  • Fixed a race condition in Websocket++ based implementation during websocket client destructor which would sometimes result in an AV/Segfault.
  • Added proxy support for Websocket++ based implementation.
  • Added support for Server Name Indication (SNI) to Websocket++ based implementation.
  • Updated server certificate verification to accept SERVER_GATED_CRYPTO and SGC_NETSCAPE usage for Websocket++ based implementation on Windows.

pplx
  • Merged a pull request lazy instantiating the underlying threadpool used. Allows for forking processes in certain circumstances. #68

http_client
  • Make std::function parameter to http_client::add_handler passed by const reference.
  • Fixed invalid check in WinHTTP based implementation causing autologon security level to be high if credentials are not provided.
  • Added extract_utf8string and extract_utf16string to http_request and http_response classes. This allows uses either UTF-8 or UTF-16, instead of utility::string_t, more efficiently regardless of the platform.
  • Implemented native handle API for non-Windows platforms exposing Boost.Asio structures. This allows for configuring additional options like client certificates for example. #168
  • Fixed bug in Boost.Asio based implementation that incorrectly caused multiple handshakes to occur when reusing connections with HTTPS.
  • Fixed bug incorrectly setting the Content-Length header when not using the "C" locale.

json
  • Fixed issue where the JSON library assumes char is a signed type, however C++ doesn't guarantee this. On ARM with Clang for example char is an unsigned type. This lead to incorrect parsing.

Miscellaneous
  • Merged pull request adding http_constants.dat to be installed with 'make install'.
  • Deprecated utility function web::http::bind, this was an implementation detail and really never should have been part of the API.
  • Added overloads that accept a std::locale for utility::conversions::print_string and utility::conversions::scan_string.
  • Fixed several locations where a stringstream was being used and assumed the "C" locale was set.
  • Merged pull request fixing bug with nullptr from SafeInt3.hpp with GCC. #340

Tests
  • Fixed race conditions in close_callback_client_from_server
  • Added proper synchronization to test_websocket_server (preventing some race conditions). #305
Viewing all 4845 articles
Browse latest View live