This commit is contained in:
Naumann 2020-06-11 13:27:04 +02:00
parent cbcc2d9217
commit 438122dbc9

View file

@ -68,37 +68,62 @@
if(isset($_POST["go"])) if(isset($_POST["go"]))
{ {
$url = 'localhost:5000/api/katalog';
$form = array( $form = array(
"Title"=>$_POST["Title"], "title"=>$_POST["Title"],
"Author"=>$_POST["Author"], "author"=>$_POST["Author"],
"Country"=>$_POST["Country"], "country"=>$_POST["Country"],
"Link"=>$_POST["Link"], "link"=>$_POST["Link"],
"Language"=>$_POST["Language"], "language"=>$_POST["Language"],
"Pages"=>$_POST["Pages"], "pages"=>$_POST["Pages"],
"Year"=>$_POST["Year"], "year"=>$_POST["Year"],
"LendTime"=>$_POST["LendTime"], "category"=>$_POST["Category"],
"Category"=>$_POST["Category"], "imageLink"=>$_POST["ImageLink"],
"ImageLink"=>$_POST["ImageLink"], "lendTime"=>$_POST["LendTime"],
"LendType"=>$_POST["LendType"]); "lendType"=>$_POST["LendType"]);
$json = json_encode($form); $json = json_encode($form);
$data = $form;
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n",
'content' => $json
)
));
// Send the request
$response= file_get_contents('http://localhost:5000/api/katalog/buch', false, $context);
echo $response;
// Check for errors
if($response === FALSE){
die('Error');
}
// Decode the response
$responseData = json_decode($response, TRUE);
// Print the date from the response
echo $responseData['productId'];
//$data = $form;
/*
// use key 'http' even if you send the request to https://... // use key 'http' even if you send the request to https://...
$options = array( $options = array(
'http' => array( 'http' => array(
'header' => "Content-type: application/json\r\n", 'header' => "Content-type: application/json\r\n",
'method' => 'POST', 'method' => 'POST',
'content' => http_build_query($data), 'content' => http_build_query($form),
), ),
); );
$context = stream_context_create($options); $context = stream_context_create($options);
//echo $context; //echo $context;
$result = file_get_contents('http://localhost:5000/api/katalog/'); // $result = file_get_contents('http://localhost:5000/api/katalog/');
echo $result; //$bloed= file_put_contents('http://localhost:5000/api/katalog/', $form, FILE_APPEND);
*/
// http://www.php.net/manual/en/context.http.php
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="de"> <html lang="de">