From 438122dbc9969312cd03bd1e1550e55ab7f12213 Mon Sep 17 00:00:00 2001 From: Naumann Date: Thu, 11 Jun 2020 13:27:04 +0200 Subject: [PATCH] . --- addKatalog.php | 59 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/addKatalog.php b/addKatalog.php index b54324a..33797da 100644 --- a/addKatalog.php +++ b/addKatalog.php @@ -68,37 +68,62 @@ if(isset($_POST["go"])) { - $url = 'localhost:5000/api/katalog'; $form = array( - "Title"=>$_POST["Title"], - "Author"=>$_POST["Author"], - "Country"=>$_POST["Country"], - "Link"=>$_POST["Link"], - "Language"=>$_POST["Language"], - "Pages"=>$_POST["Pages"], - "Year"=>$_POST["Year"], - "LendTime"=>$_POST["LendTime"], - "Category"=>$_POST["Category"], - "ImageLink"=>$_POST["ImageLink"], - "LendType"=>$_POST["LendType"]); + "title"=>$_POST["Title"], + "author"=>$_POST["Author"], + "country"=>$_POST["Country"], + "link"=>$_POST["Link"], + "language"=>$_POST["Language"], + "pages"=>$_POST["Pages"], + "year"=>$_POST["Year"], + "category"=>$_POST["Category"], + "imageLink"=>$_POST["ImageLink"], + "lendTime"=>$_POST["LendTime"], + "lendType"=>$_POST["LendType"]); $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://... $options = array( 'http' => array( 'header' => "Content-type: application/json\r\n", 'method' => 'POST', - 'content' => http_build_query($data), + 'content' => http_build_query($form), ), ); $context = stream_context_create($options); //echo $context; - $result = file_get_contents('http://localhost:5000/api/katalog/'); - echo $result; + // $result = file_get_contents('http://localhost:5000/api/katalog/'); + //$bloed= file_put_contents('http://localhost:5000/api/katalog/', $form, FILE_APPEND); + */ + // http://www.php.net/manual/en/context.http.php } -?> +?>