Autor Beitrag
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mi 30.11.16 23:43 
Der ServicePointManager.ServerCertificateValidationCallback ist eine globale Sache der hat nix mit dem HttpWebRequest den du ~zufällig~ direkt daneben programmiert hast.
Der Callback ist statisch und zieht für alle Requests. Wen du den Callback also später für andere Requests nicht mehr willst dann musst du ServerCertificateValidationCallback anschließend null zuweisen.
Csharp-programmierer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 696
Erhaltene Danke: 10

Windows 8.1
C# (VS 2013)
BeitragVerfasst: Do 01.12.16 09:27 
Ich habe ja 2 unterschiedliche Methoden, Daten an eine PHP Datei zu senden:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create("https://meineURL.com/Script.php");
                myHttpWebRequest.Method = "POST";

                myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0";
                myHttpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

                NameValueCollection nv = HttpUtility.ParseQueryString(String.Empty);
                nv["value"] = this.textBox1.Text;
                byte[] data = Encoding.ASCII.GetBytes(nv.ToString());
                myHttpWebRequest.ContentLength = data.Length;

                Stream requestStream = myHttpWebRequest.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();

                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                Stream responseStream = myHttpWebResponse.GetResponseStream();
                StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);

                string pageContent = myStreamReader.ReadToEnd();

                myStreamReader.Close();
                responseStream.Close();
                myHttpWebResponse.Close();

                MessageBox.Show(pageContent, "Page Content");


ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
string URL = @"https://meineURL/Script.php";
            WebClient webClient = new WebClient();

            NameValueCollection formData = new NameValueCollection();
            formData["value"] = this.textBox1.Text;

            byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
            string responsefromserver = Encoding.UTF8.GetString(responseBytes);
            webClient.Dispose();
            MessageBox.Show(responsefromserver);


Der Grund, warum ich den Thread eröffnet habe war, dass bei der zweiten Methode der Fehler kam, dass die Verbindung aufgrund einer Unsicherheit geschlossen wurde. Ich habe aus Spaß jetzt ein kleines Programm geschrieben, was diese beiden Methoden enthält. Mit Button1 wird die obere Methode ausgeführt und mit Button2 die untere. Beide funktionieren jetzt. Aber warum? Ich meine es gab ja anfangs Probleme?

Hier sind die Bilder von Charles, der die Datenpakete abfängt:
1
2
Einloggen, um Attachments anzusehen!
_________________
"Wer keinen Sinn im Leben sieht, ist nicht nur unglücklich, sondern kaum lebensfähig" - Albert Einstein
Csharp-programmierer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 696
Erhaltene Danke: 10

Windows 8.1
C# (VS 2013)
BeitragVerfasst: Fr 02.12.16 21:29 
Und welche der beiden Methoden ist sicherer?

_________________
"Wer keinen Sinn im Leben sieht, ist nicht nur unglücklich, sondern kaum lebensfähig" - Albert Einstein