Ok my description wasn't fully correct. I don't have to develop a RESTful architecture. A RESTFul architecture is developed and provided by a different company and from them I get an interface, where I have to communicate through my software.
I have a sample written in C#. Is it possible to realize exactly the same in VDF 17.0 or do I have to upgrade to DF 18.1?
PHP Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
namespace efstaTest
{
class Program
{
static void Main(string[] args)
{
string data = "";
//Testdaten aus XML-Datei als Text auslesen
if (File.Exists("testdaten.xml"))
data = File.ReadAllText("testdaten.xml");
//Text in Bytes konvertieren
byte[] bytes = Encoding.UTF8.GetBytes(data);
//Webrequest zum lokalen Register erstellen
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:5618/register");
//ContentType, Länge und Methode für POST-Request setzen
request.ContentType = "application/vnd.efsta.efr.v1+xml; encoding='utf-8'";
request.ContentLength = bytes.Length;
request.Method = "POST";
//Über den Requeststream die Daten in den Request schreiben
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
try
{
//Request senden und auf Antwort warten
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
//Daten aus der Antwort auslesen und auf der Console ausgeben
Stream responseStream = response.GetResponseStream();
string responseStr = new StreamReader(responseStream).ReadToEnd();
Console.WriteLine(responseStr);
}
else
{
//Wenn Statuscode nicht OK ist, Statuscode auf Console ausgeben
Console.WriteLine("Statuscode: " + response.StatusCode);
}
}
catch (Exception e)
{
//Im Fehlerfall (zB Register nicht erreichbar), Fehler auf der Console ausgeben
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}