Datenbank verbindung
This commit is contained in:
1 parent
8005078f70
commit
9a4cb99e91
2 files changed
+35
-2
No files matched your search
@@ -1,12 +1,41 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
namespace Vorprojekt
|
namespace Vorprojekt
|
||||||
{
|
{
|
||||||
internal class Backend_verbindung
|
public class Backend_verbindung
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public JsonArray Datenbank(){
|
||||||
|
//Definiert die URL der REST-API, von der Daten abgerufen werden sollen.
|
||||||
|
//BITTE ANPASSEN AN EUREN PFAD!
|
||||||
|
string url = "http://localhost/PBDGS2H25ALA/Vorprojekt/restAPI.php";
|
||||||
|
// z.B. URL fürs Einloggen zusammensetzen
|
||||||
|
//url += "/user/login?username=Hansi&password=GeheimesPasswort123";
|
||||||
|
|
||||||
|
HttpClient client = new HttpClient();
|
||||||
|
//Führt eine GET-Anfrage an die URL aus.
|
||||||
|
//Es stehen auch DeleteAsync, PostAsync und PutAsync zur Verfügung
|
||||||
|
var response = client.GetAsync(url).Result;
|
||||||
|
//Liest den Inhalt des HTTP-Response als String (eigentlich ein JSON-Array) aus
|
||||||
|
string responseString = response.Content.ReadAsStringAsync().Result;
|
||||||
|
//Parst den JSON-String in ein JsonArray-Objekt.
|
||||||
|
//JsonNode.Parse() analysiert den JSON-Text und gibt ein JsonNode zurück, das hier in ein JsonArray umgewandelt wird.
|
||||||
|
JsonArray json = (JsonArray)JsonNode.Parse(responseString);
|
||||||
|
foreach (JsonObject item in json)
|
||||||
|
{
|
||||||
|
Console.WriteLine(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,4 +8,8 @@
|
|||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Text.Json" Version="11.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in new issue
Block a user