Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin Forms HttpWebRequest with Certificate

PhilippWegenerPhilippWegener USMember ✭✭

Hello,

I have a Portable Project, which calls my asmx webservice.
I call the webservice with httpwebrequest and send an certificate to the Server.
In Android everything is working fine, but in iOS i cant send the certificate.
Did i have to use ModernHttpClient?

Following Code works in Android:

    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://*****");
    req.Method = "POST";
    req.ContentType = "application/json";

    DependencyService.Get<IWebservice>().ApplyCertificate(req);

    byte[] postDataAsBytesS = Encoding.UTF8.GetBytes(mobileJSON);
    Stream postStreamS = req.GetRequestStream();
    postStreamS.Write(postDataAsBytesS, 0, postDataAsBytesS.Length);
    postStreamS.Flush();
    postStreamS.Dispose();

    WebResponse resS = req.GetResponse(); //Error in iOS
    postStreamS = resS.GetResponseStream();
    StreamReader srS = new StreamReader(postStreamS);

    string responseFromServerS = srS.ReadToEnd();

Everytime i send the request, i get an error back from Server.
What can i do?

Thanks

Tagged:
Sign In or Register to comment.