22
votes

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?

3
I think you have to add certificate to your device: [Mono Certificate Manager >> certmgr ](linux.die.net/man/1/certmgr)huse.ckr
looks like it is missing a certificateWesam
my workaround has helped you ?gmetax
@gmetax no sadly this seems to have no effektquadroid
maybe your problem is for raspberry, try to reinstall ca-certificate with --fix-missinggmetax

3 Answers

3
votes

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

1
votes

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
0
votes

Hi friend i have a line of code which is working for other Place is working fine. You may try this :

Request and response web form using Post Method in same page c# asp.net