Implementation Samples
curl (Windows)
Command line call for signature
curl.exe -o outputSign.txt --cacert cas.pem -X POST -H "Content-Type: application/json" -d @requestSign.json https://.../v2/u123456789/Sign
requestSign.json
{
"password":"123456789",
"to_be_signed":"c2FtcGxlIHRleHQgZ...WNl"
}
outputSign.txt
{
"signature":"GkXDFLK3C...feJhPwAA==",
}
command line call for reading certificate information
curl.exe -o outputCert.txt --cacert cas.pem -X GET https://.../v2/u123456789/Certificate
outputCert.txt
{
"Signaturzertifikat":"MIIE...QA6o=",
"Zertifizierungsstellen":["MII...WSF"],
"Zertifikatsseriennummer":"963244432",
"alg":"ES256"
}
command line call for reading certificate authority information
curl.exe -o outputZDA.txt --cacert cas.pem -X GET https://.../v2/u123456789/ZDA
outputZDA.txt
{
"zdaid":"AT1"
}
Request with C-Sharp
string URL = "https://.../v2/u123456789/Sign";
string request = @"{
""password"":""123456789"",
""to_be_signed"":""c2Ftc...SBzZXJ2aWNl""
}";
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(request);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(URL);
webRequest.Method = "POST";
webRequest.ContentType = "application/json";
webRequest.ContentLength = data.Length;
webRequest.GetRequestStream().Write(data, 0, data.Length);
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader reader = new StreamReader(webResponse.GetResponseStream(), System.Text.UTF8Encoding.UTF8);
string ResponseText = reader.ReadToEnd();
Request with Java
String urlStr = "https://.../v2/u123456789/Sign";
String request = "{\"password\":\"123456789\", \"to_be_signed\":\"c2FtcGxl...XJ2aWNl\"}";
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Content-Type", "application/json");
OutputStream out = conn.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
writer.write(request);
writer.close();
out.close();
if (conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
String responseStr = sb.toString();
Request with PHP
<?php
$url = 'https://.../v2/u123456789/Sign';
$data = '{"password":"123456789","to_be_signed":"c2FtcGx...ZXJ2aWNl"}';
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => $data,
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
?>
Based on the stackoverflow answer https://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php#6609181.