Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Https POST/GET not working on Mono

I want to execute a HttpPost on a Raspberry using Mono + Restsharp.

The Httpie call that i try to reproduce in code looks something like this:

 http POST https://XXXXX.azurewebsites.net/api/report key=value

This is the C# code:

RestClient nodeRed = new RestClient("http://XXXXX.azurewebsites.net/");
var request = new RestRequest("api/report", Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddBody(new { Timestamp = DateTime.Now, Data = "Test" });
request.Timeout = 5000;

var response = nodeRed.Execute(request);

The code runs fine, it is just not working. The Response does not contain any content (server response with "Success" on httpie / MS .NET Framework).

I already found out about the Certificate stuff on Mono. Running

sudo certmgr -ssl -v -m "https://XXXXX.azurewebsites.net"

Tells me it Adds two certificates on the first time. Running it again does add the first Certificate again (and again) like it is not working.

X.509 Certificate v3 Issued from: C=IE, O=Baltimore, OU=CyberTrust, CN=Baltimore CyberTrust Root Issued to: C=US, S=Washington, L=Redmond, O=Microsoft Corporation, OU=Microsoft IT, CN=Microsoft IT SSL SHA2 Valid from: 19/12/2013 20:07:32 Valid until: 19/12/2017 20:06:55 WARNING: Certificate signature is INVALID Import this certificate into the CA store ?

If i confirm and repeat the import, certmgr asks me to import again. How can i get the http post to work?

like image 456
quadroid Avatar asked Sep 05 '16 13:09

quadroid


People also ask

How do I install the Mono packages?

We’ll install the Mono packages from the official Mono’s repositories: Install the dependencies necessary to add a new repository over HTTPS: mono-complete is a meta-package that installs the Mono runtime, development tools, and all libraries. The installation may take a few minutes to complete.

What is the latest version of Mono?

mono-complete is a meta-package that installs the Mono runtime, development tools, and all libraries. The installation may take a few minutes to complete. Once completed, verify it by typing the following command which will print the Mono version: At the time of writing this article, the latest stable version of Mono is 6.8.0.123.

Why can't I install Mono/MonoDevelop on Raspberry-Pi?

Sorry, something went wrong. Since Raspberry-Pi stepped up from 3 to 4, installing Mono/Monodevelop to Raspberry-Pi wasn't be a straight-forward process. So, you can't install recent version/release Mono/Monodevelop to Raspberry-Pi. I found my way through the issue #8304. First, I succeded with Raspberry-Pi4 Rev 1.2.

How do I block the execution of Hello world in mono?

Mono<String> blockingHelloWorld() { return Mono.just ( "Hello world!" ); } String result = blockingHelloWorld ().block (); assertEquals ( "Hello world!", result); Here, we're blocking the execution as long as the publisher doesn't emit the value. However, it can take any amount of time to finish.


Video Answer


2 Answers

You can try to ignore certificates with that

ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;

Update
as I can see here exists on Mono also

like image 136
gmetax Avatar answered Sep 28 '22 06:09

gmetax


It must have some connection to Mono By default not trusting any ssl certificate... well check thess article out http://www.mono-project.com/docs/faq/security/ https://github.com/restsharp/RestSharp/issues/728 https://github.com/dotnet/roslyn/issues/7422

or You need to use openssl for analyzing the certificate:

    openssl s_client -showcerts -connect www.domain.com:443
openssl x509 -text -noout -in some.crt
like image 39
youngdero Avatar answered Sep 28 '22 07:09

youngdero