why certificates are null using .NET Core 2 but it works just fine with .NET Framework 4.6.2?Django Authentication from .NET using HttpWebRequest and HttpWebResponse via HTTP POSTUnable to set cookies with web browser controls in windows phone appReferencing .net framework assemblies in .net core 2 that rely on the ConfigurationManagerIs there anyway to use a third-party library that has been created for .NET Framework, in .NET Core 2.0?.Net Core 2.0 Log4Net AdoNetAppender isn't workingWhy doesn't garbage collector in net core 2.0 free all memory.Net Core 2.0 solution with .Net Framework project dependencies - Could not load file or assembly 'System.ServiceModel'How to track in Entry Framework that Record has been created successfully .NET Core 2.0.Net Core 2.0 Webservice and TLS 1.2/certificate.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase is not working in .net core 2.1?

Has J.J.Jameson ever found out that Peter Parker is Spider-Man?

Is the "muddled thoughts" from Synaptic Static a magical effect?

(7 of 11: Fillomino) What is Pyramid Cult's Favorite Shape?

Where can I see modifications made to the PATH environment variable by the Go installer

On the expression "sun-down"

How were x-ray diffraction patterns deciphered before computers?

Skipping same old introductions

Does the problem of P vs NP come under the category of Operational Research?

Difference between "jail" and "prison" in German

How does shared_ptr<void> know which destructor to use?

Why isn't the new LEGO CV joint available on Bricklink or Brickowl?

Phase portrait of a system of differential equations

how to change ^L code in many files in ubuntu?

Password management for kids - what's a good way to start?

Can I say "Gesundheit" if someone is coughing?

Why are sugars in whole fruits not digested the same way sugars in juice are?

Astable 555 circuit not oscillating

Can an unintentional murderer leave Ir Miklat for Shalosh Regalim?

Search and replace a substring only if another substring is not present

Does proof-of-work contribute directly to prevent double-spending?

Partial Fractions: Why does this shortcut method work?

Why adjustbox needs a tweak of raise=-0.3ex with enumitem?

Gold Battle KoTH

Can you shove a friendly creature?



why certificates are null using .NET Core 2 but it works just fine with .NET Framework 4.6.2?


Django Authentication from .NET using HttpWebRequest and HttpWebResponse via HTTP POSTUnable to set cookies with web browser controls in windows phone appReferencing .net framework assemblies in .net core 2 that rely on the ConfigurationManagerIs there anyway to use a third-party library that has been created for .NET Framework, in .NET Core 2.0?.Net Core 2.0 Log4Net AdoNetAppender isn't workingWhy doesn't garbage collector in net core 2.0 free all memory.Net Core 2.0 solution with .Net Framework project dependencies - Could not load file or assembly 'System.ServiceModel'How to track in Entry Framework that Record has been created successfully .NET Core 2.0.Net Core 2.0 Webservice and TLS 1.2/certificate.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase is not working in .net core 2.1?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have been doing some test migrating .NET Framework 4.6.2 apps to .NET Core 2. I noticed that this particular app, a monitoring http is not working fine with Net Core 2. Can you please help me to verify what is happening?



static void Main(string[] args)

try

HttpWebRequest myhttpWebReqest = (HttpWebRequest)WebRequest.Create("https://www.google.com.mx/");
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myhttpWebReqest.GetResponse();
timer.Stop();
TimeSpan timeSpan = timer.Elapsed;
Console.WriteLine(timeSpan.ToString());
Console.WriteLine();
Console.WriteLine(myHttpWebResponse.StatusCode);
Console.WriteLine((int)myHttpWebResponse.StatusCode);
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.GetEffectiveDateString());
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.GetExpirationDateString());
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.Issuer);
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.Subject);

catch (Exception ex)

Console.WriteLine(ex.Message);
if(ex.InnerException !=null)

Console.WriteLine(ex.InnerException);


Console.ReadLine();

}


in the .NET Framework 4.6.2 i see the certificate data, in the .NET Core 2 i see myhttpWebReqest.ServicePoint.Certificate null ... do you know why?










share|improve this question
























  • question is also here

    – David Alejandro García García
    Apr 9 at 20:05











  • Why are you using HttpWebRequest at all? Even in 4.6.2 the preferred way is to use HttpClient. HttpClient uses handlers to configure retries, compression, certificates

    – Panagiotis Kanavos
    Apr 18 at 15:53


















0















I have been doing some test migrating .NET Framework 4.6.2 apps to .NET Core 2. I noticed that this particular app, a monitoring http is not working fine with Net Core 2. Can you please help me to verify what is happening?



static void Main(string[] args)

try

HttpWebRequest myhttpWebReqest = (HttpWebRequest)WebRequest.Create("https://www.google.com.mx/");
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myhttpWebReqest.GetResponse();
timer.Stop();
TimeSpan timeSpan = timer.Elapsed;
Console.WriteLine(timeSpan.ToString());
Console.WriteLine();
Console.WriteLine(myHttpWebResponse.StatusCode);
Console.WriteLine((int)myHttpWebResponse.StatusCode);
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.GetEffectiveDateString());
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.GetExpirationDateString());
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.Issuer);
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.Subject);

catch (Exception ex)

Console.WriteLine(ex.Message);
if(ex.InnerException !=null)

Console.WriteLine(ex.InnerException);


Console.ReadLine();

}


in the .NET Framework 4.6.2 i see the certificate data, in the .NET Core 2 i see myhttpWebReqest.ServicePoint.Certificate null ... do you know why?










share|improve this question
























  • question is also here

    – David Alejandro García García
    Apr 9 at 20:05











  • Why are you using HttpWebRequest at all? Even in 4.6.2 the preferred way is to use HttpClient. HttpClient uses handlers to configure retries, compression, certificates

    – Panagiotis Kanavos
    Apr 18 at 15:53














0












0








0








I have been doing some test migrating .NET Framework 4.6.2 apps to .NET Core 2. I noticed that this particular app, a monitoring http is not working fine with Net Core 2. Can you please help me to verify what is happening?



static void Main(string[] args)

try

HttpWebRequest myhttpWebReqest = (HttpWebRequest)WebRequest.Create("https://www.google.com.mx/");
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myhttpWebReqest.GetResponse();
timer.Stop();
TimeSpan timeSpan = timer.Elapsed;
Console.WriteLine(timeSpan.ToString());
Console.WriteLine();
Console.WriteLine(myHttpWebResponse.StatusCode);
Console.WriteLine((int)myHttpWebResponse.StatusCode);
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.GetEffectiveDateString());
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.GetExpirationDateString());
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.Issuer);
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.Subject);

catch (Exception ex)

Console.WriteLine(ex.Message);
if(ex.InnerException !=null)

Console.WriteLine(ex.InnerException);


Console.ReadLine();

}


in the .NET Framework 4.6.2 i see the certificate data, in the .NET Core 2 i see myhttpWebReqest.ServicePoint.Certificate null ... do you know why?










share|improve this question














I have been doing some test migrating .NET Framework 4.6.2 apps to .NET Core 2. I noticed that this particular app, a monitoring http is not working fine with Net Core 2. Can you please help me to verify what is happening?



static void Main(string[] args)

try

HttpWebRequest myhttpWebReqest = (HttpWebRequest)WebRequest.Create("https://www.google.com.mx/");
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myhttpWebReqest.GetResponse();
timer.Stop();
TimeSpan timeSpan = timer.Elapsed;
Console.WriteLine(timeSpan.ToString());
Console.WriteLine();
Console.WriteLine(myHttpWebResponse.StatusCode);
Console.WriteLine((int)myHttpWebResponse.StatusCode);
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.GetEffectiveDateString());
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.GetExpirationDateString());
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.Issuer);
Console.WriteLine();
Console.WriteLine(myhttpWebReqest.ServicePoint.Certificate.Subject);

catch (Exception ex)

Console.WriteLine(ex.Message);
if(ex.InnerException !=null)

Console.WriteLine(ex.InnerException);


Console.ReadLine();

}


in the .NET Framework 4.6.2 i see the certificate data, in the .NET Core 2 i see myhttpWebReqest.ServicePoint.Certificate null ... do you know why?







httpwebrequest .net-core-2.0 system.net.httpwebrequest






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 1:26









David Alejandro García GarcíaDavid Alejandro García García

778 bronze badges




778 bronze badges















  • question is also here

    – David Alejandro García García
    Apr 9 at 20:05











  • Why are you using HttpWebRequest at all? Even in 4.6.2 the preferred way is to use HttpClient. HttpClient uses handlers to configure retries, compression, certificates

    – Panagiotis Kanavos
    Apr 18 at 15:53


















  • question is also here

    – David Alejandro García García
    Apr 9 at 20:05











  • Why are you using HttpWebRequest at all? Even in 4.6.2 the preferred way is to use HttpClient. HttpClient uses handlers to configure retries, compression, certificates

    – Panagiotis Kanavos
    Apr 18 at 15:53

















question is also here

– David Alejandro García García
Apr 9 at 20:05





question is also here

– David Alejandro García García
Apr 9 at 20:05













Why are you using HttpWebRequest at all? Even in 4.6.2 the preferred way is to use HttpClient. HttpClient uses handlers to configure retries, compression, certificates

– Panagiotis Kanavos
Apr 18 at 15:53






Why are you using HttpWebRequest at all? Even in 4.6.2 the preferred way is to use HttpClient. HttpClient uses handlers to configure retries, compression, certificates

– Panagiotis Kanavos
Apr 18 at 15:53













1 Answer
1






active

oldest

votes


















1














See discussion of this here: https://github.com/dotnet/corefx/issues/36979



ServicePointManager and ServicePoint classes are no-op on .NET Core. But you can do a similar thing with HttpClient. HttpClient is the more modern and preferred HTTP API in .NET Framework and .NET Core.



using System;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace NetCoreConsoleApp1

class Program

static void Main(string[] args)

var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = CustomCallback;
var client = new HttpClient(handler);

HttpResponseMessage response = client.GetAsync("https://www.google.com.mx/").GetAwaiter().GetResult();
Console.WriteLine(response.StatusCode);
Console.WriteLine((int)response.StatusCode);


private static bool CustomCallback(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)

Console.WriteLine(arg2.GetEffectiveDateString());
Console.WriteLine(arg2.GetExpirationDateString());
Console.WriteLine(arg2.Issuer);
Console.WriteLine(arg2.Subject);

return arg4 == SslPolicyErrors.None;








share|improve this answer

























  • thank you David - MSFT. aparently HttpWebRequest API is obsolete now. more details HERE

    – David Alejandro García García
    May 3 at 4:14











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368470%2fwhy-certificates-are-null-using-net-core-2-but-it-works-just-fine-with-net-fra%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














See discussion of this here: https://github.com/dotnet/corefx/issues/36979



ServicePointManager and ServicePoint classes are no-op on .NET Core. But you can do a similar thing with HttpClient. HttpClient is the more modern and preferred HTTP API in .NET Framework and .NET Core.



using System;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace NetCoreConsoleApp1

class Program

static void Main(string[] args)

var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = CustomCallback;
var client = new HttpClient(handler);

HttpResponseMessage response = client.GetAsync("https://www.google.com.mx/").GetAwaiter().GetResult();
Console.WriteLine(response.StatusCode);
Console.WriteLine((int)response.StatusCode);


private static bool CustomCallback(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)

Console.WriteLine(arg2.GetEffectiveDateString());
Console.WriteLine(arg2.GetExpirationDateString());
Console.WriteLine(arg2.Issuer);
Console.WriteLine(arg2.Subject);

return arg4 == SslPolicyErrors.None;








share|improve this answer

























  • thank you David - MSFT. aparently HttpWebRequest API is obsolete now. more details HERE

    – David Alejandro García García
    May 3 at 4:14
















1














See discussion of this here: https://github.com/dotnet/corefx/issues/36979



ServicePointManager and ServicePoint classes are no-op on .NET Core. But you can do a similar thing with HttpClient. HttpClient is the more modern and preferred HTTP API in .NET Framework and .NET Core.



using System;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace NetCoreConsoleApp1

class Program

static void Main(string[] args)

var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = CustomCallback;
var client = new HttpClient(handler);

HttpResponseMessage response = client.GetAsync("https://www.google.com.mx/").GetAwaiter().GetResult();
Console.WriteLine(response.StatusCode);
Console.WriteLine((int)response.StatusCode);


private static bool CustomCallback(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)

Console.WriteLine(arg2.GetEffectiveDateString());
Console.WriteLine(arg2.GetExpirationDateString());
Console.WriteLine(arg2.Issuer);
Console.WriteLine(arg2.Subject);

return arg4 == SslPolicyErrors.None;








share|improve this answer

























  • thank you David - MSFT. aparently HttpWebRequest API is obsolete now. more details HERE

    – David Alejandro García García
    May 3 at 4:14














1












1








1







See discussion of this here: https://github.com/dotnet/corefx/issues/36979



ServicePointManager and ServicePoint classes are no-op on .NET Core. But you can do a similar thing with HttpClient. HttpClient is the more modern and preferred HTTP API in .NET Framework and .NET Core.



using System;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace NetCoreConsoleApp1

class Program

static void Main(string[] args)

var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = CustomCallback;
var client = new HttpClient(handler);

HttpResponseMessage response = client.GetAsync("https://www.google.com.mx/").GetAwaiter().GetResult();
Console.WriteLine(response.StatusCode);
Console.WriteLine((int)response.StatusCode);


private static bool CustomCallback(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)

Console.WriteLine(arg2.GetEffectiveDateString());
Console.WriteLine(arg2.GetExpirationDateString());
Console.WriteLine(arg2.Issuer);
Console.WriteLine(arg2.Subject);

return arg4 == SslPolicyErrors.None;








share|improve this answer













See discussion of this here: https://github.com/dotnet/corefx/issues/36979



ServicePointManager and ServicePoint classes are no-op on .NET Core. But you can do a similar thing with HttpClient. HttpClient is the more modern and preferred HTTP API in .NET Framework and .NET Core.



using System;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace NetCoreConsoleApp1

class Program

static void Main(string[] args)

var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = CustomCallback;
var client = new HttpClient(handler);

HttpResponseMessage response = client.GetAsync("https://www.google.com.mx/").GetAwaiter().GetResult();
Console.WriteLine(response.StatusCode);
Console.WriteLine((int)response.StatusCode);


private static bool CustomCallback(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)

Console.WriteLine(arg2.GetEffectiveDateString());
Console.WriteLine(arg2.GetExpirationDateString());
Console.WriteLine(arg2.Issuer);
Console.WriteLine(arg2.Subject);

return arg4 == SslPolicyErrors.None;









share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 18 at 15:50









David - MSFTDavid - MSFT

1062 bronze badges




1062 bronze badges















  • thank you David - MSFT. aparently HttpWebRequest API is obsolete now. more details HERE

    – David Alejandro García García
    May 3 at 4:14


















  • thank you David - MSFT. aparently HttpWebRequest API is obsolete now. more details HERE

    – David Alejandro García García
    May 3 at 4:14

















thank you David - MSFT. aparently HttpWebRequest API is obsolete now. more details HERE

– David Alejandro García García
May 3 at 4:14






thank you David - MSFT. aparently HttpWebRequest API is obsolete now. more details HERE

– David Alejandro García García
May 3 at 4:14









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368470%2fwhy-certificates-are-null-using-net-core-2-but-it-works-just-fine-with-net-fra%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?