Hello everyone,
I want to do a easy Https request.
I've searched a long time in the internet and found code like this:ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
But this code isnt working...
I have crated an easy http request, which works very good:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { var encoding = Encoding.GetEncoding(response.CharacterSet); using (Stream responseStream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(responseStream, encoding)) return reader.ReadToEnd(); }
But i need an Https Request. So how can I do that?
Thank you!
i m sorry but not really time to explain here is it a sample who works and there are a lot of sample on google
your goal is to get a json data ?
`
const string URL_PIZZA = "http://www.pizzaboy.de/app/pizzaboy.json";
async Task GetAllPizzasDatas()
{
var httpClient = HttpClientApi.GetHttpClient();
var response = await httpClient.GetAsync(URL_PIZZA);
if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); return content; } return null; }
public class HttpClientApi
{
public static HttpClient GetHttpClient()
{
//
var httpClient = new HttpClient();
// httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); return httpClient; } }
`
copy paste the code, and on click on button call yourclass.GetAllPizzasData()
Answers
Hello @JonasPTFL
never try but i've found perhpas something who can help you ..
https://stackoverflow.com/questions/22251689/make-https-call-using-httpclient
https://docs.microsoft.com/fr-fr/xamarin/cross-platform/app-fundamentals/transport-layer-security?tabs=vswin
I didnt succes!
i m sorry but not really time to explain here is it a sample who works and there are a lot of sample on google
your goal is to get a json data ?
`
const string URL_PIZZA = "http://www.pizzaboy.de/app/pizzaboy.json";
async Task GetAllPizzasDatas()
{
var httpClient = HttpClientApi.GetHttpClient();
var response = await httpClient.GetAsync(URL_PIZZA);
public class HttpClientApi
{
public static HttpClient GetHttpClient()
{
//
var httpClient = new HttpClient();
`
copy paste the code, and on click on button call yourclass.GetAllPizzasData()
Hello @JonasPTFL thanks for having validate the answer
don't forget to add a try catch 
No problem.
I have tryed the code in my App but there is a misstake in
return content;
orreturn null;