# How to make a HTTPS POST request

**URL:** <https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281>\
**Category:** Developing Cinder\
**Created:** [September 24, 2016, 2:16am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281 "2016-09-24T02:16:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nay](https://avatars.discourse-cdn.com/v4/letter/n/8e7dd6/32.png) [@nay](https://discourse.libcinder.org/u/nay)\
**Post date:** [September 24, 2016, 2:16am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/1 "2016-09-24T02:16:01Z")

</div>

Hi all,

I need to integrate with backend at the moment that requires I make a HTTPS POST request with an Authorization HTTP header, which I have not done before. I am deploying on Windows but developing on OSX. As the built in URL functionality doe not support POST what’s the best way to go about this? From looking at available blocks:

- [Cinder-Protocol](https://github.com/BanTheRewind/Cinder-Protocol) does not seem to currently work with HTTPS.
- [Cinder-Asio ssl branch](https://github.com/BanTheRewind/Cinder-Asio/tree/ssl) seems to be missing some of the recent changes to master that enabled it to compiled with ASIO standalone and latest cinder
- [Cinder-Curl](https://github.com/bgbotond/Cinder-Curl) is no longer maintained and does not compile

So I thought I’d try to build something bare bones using ASIO. These links seem helpful:

- [http://stackoverflow.com/questions/22059026/connecting-to-an-https-server-with-boostasio](http://stackoverflow.com/questions/22059026/connecting-to-an-https-server-with-boostasio)
- [http://pragmaticjoe.blogspot.com.au/2015/02/boostasio-https-client.html](http://pragmaticjoe.blogspot.com.au/2015/02/boostasio-https-client.html)

I created a sample that installs with tinderbox and compiles with OSX based on the latter if anyone wants to take a look:

> <https://github.com/codeoncanvas/coc-openssl/blob/master/ci-samples/HttpsClient/src/SimpleHttpsClient.h>

But I am getting some runtime `EXC_BAD_ACCESS` errors that _seem_ to have something to do with callbacks, perhaps due to porting code from boost asio to standalone asio (changing `placeholder` and `error_code` types). The sample seems like it would be straight forward for anyone more familiar with asio so if anyone can offer any advice that would be great!

Cheers,  
nay.

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [September 24, 2016, 2:31am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/2 "2016-09-24T02:31:55Z")

</div>

Hi nay,

I’ve been working on an http client with ease of use in mind…[https://github.com/ryanbartley/Cinder-HTTP](https://github.com/ryanbartley/Cinder-HTTP). It has ssl functionality and, hopefully, an easy way to create and set headers. I haven’t worked with post too much but it should be an easy add. I’ll take a look at adding it tomorrow.

---

<div class="post-metadata">

**Author:** ![nay](https://avatars.discourse-cdn.com/v4/letter/n/8e7dd6/32.png) [@nay](https://discourse.libcinder.org/u/nay)\
**Post date:** [September 24, 2016, 4:11am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/3 "2016-09-24T04:11:22Z")

</div>

Wow, thanks Ryan. That would be amazing - the block looks great!

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [September 24, 2016, 7:14am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/4 "2016-09-24T07:14:30Z")

</div>

Hi,

I’ve recently used Microsoft’s C++ REST SDK in a project and was impressed by its ease of use. Rather surprisingly for a Microsoft library, it is cross-platform and open-source. It supports SSL out of the box, so you can make HTTPS requests and it uses PPL for pretty cool task-based asynchronous coding.

For the library itself, see:

> **[microsoft/cpprestsdk](https://github.com/Microsoft/cpprestsdk)**
>
> The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to an...

I’ve created a block that makes it easier to add the SDK to your project, but I have only tested it on Windows and I offer NO SUPPORT whatsoever, so you’re on your own. You can find it here:

> **[paulhoux/Cinder-CppRESTSDK](https://github.com/paulhoux/Cinder-CppRESTSDK)**
>
> Allows you to easily add Microsoft's CppRESTSDK to your project. - paulhoux/Cinder-CppRESTSDK

-Paul

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [September 24, 2016, 8:35am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/5 "2016-09-24T08:35:53Z")

</div>

Just as a counter point, I have a rather different opinion on REST. It became overwhelming and cumbersome to use it in a recent Mac project as everything has to be wrapped by defines because of the archaic win32 wide char stuff. The above block was written to get away from REST, in fact. It’s been used in production. So, it’s been pretty thoroughly tested.

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [September 24, 2016, 5:39pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/6 "2016-09-24T17:39:57Z")

</div>

FYI, I added a post example to the block and made a few changes. Let me know if you end up using it and if you have any problems.

---

<div class="post-metadata">

**Author:** ![colin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/colin/32/604_2.png) [@colin](https://discourse.libcinder.org/u/colin)\
**Post date:** [September 24, 2016, 6:11pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/7 "2016-09-24T18:11:13Z")

</div>

Hello,  
I use POCO for HTTP communication :  
[https://pocoproject.org/](https://pocoproject.org/)  
It work fine !

---

<div class="post-metadata">

**Author:** ![nay](https://avatars.discourse-cdn.com/v4/letter/n/8e7dd6/32.png) [@nay](https://discourse.libcinder.org/u/nay)\
**Post date:** [September 25, 2016, 12:05am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/8 "2016-09-25T00:05:46Z")

</div>

Thanks everyone,

@paul.houx - thanks for the info but old prejudices make me very apprehensive to incorporate a MS SDK into a cross platform app. It’s great to see MS changing the way they deal with OSS though so I might have to rethink that!

@colin - thanks although I’m reluctant to add a dependancy as large as poco to a project given that cinder already has boost in it, which _should_ cater for the same needs

@ryanbartley - thanks so much for adding that so quickly! I am getting a couple compile errors:

- missing `std::` from `make_shared` in `responder.hpp`
- then in `requester.hpp` I am not sure what to do about:

`/Applications/_cinder/Cinder.git/blocks/Cinder-HTTP/src/cinder/http/requester.hpp:30:16: No matching constructor for initialization of 'std::ostream' (aka 'basic_ostream<char>')`

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [September 25, 2016, 12:58am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/9 "2016-09-25T00:58:02Z")

</div>

Oh no, got a little loose when I pushed it. Surprised that Windows allows that and Mac doesn’t. I’ve seen the problem in Linux, but I had to leave before I could figure out what’s going on. I’ll take a look when I get back tonight. Sorry about that.

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [September 25, 2016, 4:10am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/10 "2016-09-25T04:10:04Z")

</div>

I was able to get the Request\_Response sample to work on OSX by removing the second argument to the ostream on the line you mentioned. This would then crash in the `onHandshake` callback in request\_response.hpp:115, where the `content` buffer is `nullptr`. Wrapping that in an `if (content){}` should band-aid you for a bit until ryan can sort out a proper fix.

---

<div class="post-metadata">

**Author:** ![nay](https://avatars.discourse-cdn.com/v4/letter/n/8e7dd6/32.png) [@nay](https://discourse.libcinder.org/u/nay)\
**Post date:** [September 25, 2016, 5:04am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/11 "2016-09-25T05:04:21Z")

</div>

Thanks, doing that and fixing a library path in the project settings did the trick!

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [September 25, 2016, 6:26am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/12 "2016-09-25T06:26:42Z")

</div>

Hey nay,

Sorry about all the trouble tonight. I pushed changes to a bunch of the stuff mentioned above and also some changes to the interface that I had wanted to make a while back. They’re now in master. @lithium, thanks for the interim help. @nay, if you had to make a change to the xcode project, feel free to pr. My mac’s hard drive failed yesterday so I wasn’t able to check the changes thoroughly enough. I should be up and running again tomorrow. And feel free to PM me or open issues on the repo with anything you find and I’ll try to be right on it.

Best,  
Ryan

---

<div class="post-metadata">

**Author:** ![nay](https://avatars.discourse-cdn.com/v4/letter/n/8e7dd6/32.png) [@nay](https://discourse.libcinder.org/u/nay)\
**Post date:** [September 25, 2016, 6:40am UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/13 "2016-09-25T06:40:19Z")

</div>

Ah no, sorry to hear about the hard drive! Just made a pull request for that project fix. Thanks again!

---

<div class="post-metadata">

**Author:** ![keithters](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/keithters/32/183_2.png) [@keithters](https://discourse.libcinder.org/u/keithters)\
**Post date:** [March 17, 2017, 7:55pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/14 "2017-03-17T19:55:52Z")

</div>

@ryanbartley,

Love, love, your Cinder-HTTP block, but a question:

Any advice on constructing a ‘multipart/form-data;’ POST request? I would love to have an easy way to upload multiple images and/or send data points to an api endpoint from cinder, but failing at every turn.

In python, i would do something like:

```
import requests

files = {}
files['image0'] = open(image0_path, 'rb')
files['image1'] = open(image1_path, 'rb')

data = {}
data['test'] = "This is totally a test."

r = requests.post(endpoint, files=files, data=data)

```

In Cinder, am faltering on how to construct that part of the request via:

```
request->appendHeader( http::Content( std::string( "multipart/form-data;" ), data ) );

```

Any Advice?

Keith

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [March 17, 2017, 8:09pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/15 "2017-03-17T20:09:19Z")

</div>

Hi,

Happy it’s getting some use. So, to be honest I haven’t worked much with the multipart stuff. What error are you seeing? Client or server side?

---

<div class="post-metadata">

**Author:** ![balachandran\_c](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@balachandran\_c](https://discourse.libcinder.org/u/balachandran_c)\
**Post date:** [March 17, 2017, 8:15pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/16 "2017-03-17T20:15:35Z")

</div>

Hi,  
Does this [SO post](http://stackoverflow.com/questions/13968134/poco-how-to-upload-image-to-webser-using-poco-in-c) help?

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [March 17, 2017, 8:36pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/17 "2017-03-17T20:36:14Z")

</div>

Looking into it a bit more, it looks as though the form data needs to be separated with a section header that doesn’t exist in any of your form data or files. This link…[http://stackoverflow.com/questions/8659808/how-does-http-file-upload-work/8660740...shows](http://stackoverflow.com/questions/8659808/how-does-http-file-upload-work/8660740...shows) what the data should look like. This weekend I can take a stab at trying to encapsulate something similar to the way poco’s wrapped it.

---

<div class="post-metadata">

**Author:** ![keithters](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/keithters/32/183_2.png) [@keithters](https://discourse.libcinder.org/u/keithters)\
**Post date:** [March 17, 2017, 8:48pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/18 "2017-03-17T20:48:23Z")

</div>

That would be amazing.

I’ve tried a few attempts at building a raw HTTP string that will work, but haven’t had any success getting the form data to show up on the server. I was basing my attempts off [https://www.huyng.com/posts/under-the-hood-an-http-request-with-multipartform-data](https://www.huyng.com/posts/under-the-hood-an-http-request-with-multipartform-data)

I’ll keep digging too, but you may have better luck being more familiar with your block.

Thanks!

Keith

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [March 17, 2017, 9:58pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/19 "2017-03-17T21:58:08Z")

</div>

~removed my post as I already wrote something similar higher up in this thread.~

---

<div class="post-metadata">

**Author:** ![Craigson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/craigson/32/43_2.png) [@Craigson](https://discourse.libcinder.org/u/Craigson)\
**Post date:** [August 9, 2017, 6:04pm UTC](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281/20 "2017-08-09T18:04:30Z")

</div>

@ryanbartley I’m getting a strange error trying to compile an app with Cinder-HTTP master branch on Win10 with VS2013:

```
Error	11	error C3646: 'noexcept' : unknown override specifier	c:\users\Craig\desktop\cinder_0.9.0_vc2013\cinder_0.9.0_vc2013\blocks\cinder-http\src\cinder\http\error_codes.ipp	26	1	HTTPapp

```

From digging through stackoverflow it looks like ‘noexcept’ is not supported in VS2013, which presumably means this line in error\_codes.ipp is the issue?

`#define URDL_ERROR_CATEGORY_NOEXCEPT noexcept`

have you run into this before?

[Next page](https://discourse.libcinder.org/t/how-to-make-a-https-post-request/281.md?page=2)
