tested pasta

This commit is contained in:
Naumann 2020-06-10 14:32:20 +02:00
parent 4bf926b8e3
commit bc5ab4adc9
2 changed files with 20 additions and 13 deletions

View file

@ -14,21 +14,25 @@
?> ?>
<?php <?php
fsockopen('www.google.com', 80);
//Zugriff auf API //Zugriff auf API
if(isset($_POST["go"])) if(isset($_POST["go"]))
{ {
$Title= $_POST['Title']; $Title= $_POST['Title'];
$url= "tcp://localhost:5000/api/katalog"; // stimmt die URL? $url= "https://localhost:5001/api/katalog"; // stimmt die URL?
$client = curl_init($url); $client = curl_init($url);
$result= file_get_contents($url);
//echo $response; //$fp = @fsockopen($client, 80, $errno, $errstr);
$fp = @fsockopen($client, 5000, $errno, $errstr); $response=curl_exec($url);
$response=curl_exec($client);
echo $errstr; echo $errstr;
//echo $fp; //echo $fp;
echo $response;
$result = json_decode($response); $result = json_decode($response);
echo $result;
$form = array( $form = array(
"Title"=>$_POST["Title"], "Title"=>$_POST["Title"],
"Author"=>$_POST["Author"]); "Author"=>$_POST["Author"]);

View file

@ -1,6 +1,6 @@
<?php <?php
if(isset($_POST['link'])) { if(isset($_GET['link'])) {
$link = $_POST['link']; $link = $_GET['link'];
//remove protocol, we're assuming its http //remove protocol, we're assuming its http
if(strstr($link, '://') != false){ if(strstr($link, '://') != false){
@ -15,6 +15,7 @@ if(isset($_POST['link'])) {
$fp = @fsockopen($host, 80, $errno, $errstr); $fp = @fsockopen($host, 80, $errno, $errstr);
if($fp == false){ if($fp == false){
$response= "Hallo";
$response = $errno . " " . $errstr; $response = $errno . " " . $errstr;
} }
else { else {
@ -22,24 +23,26 @@ if(isset($_POST['link'])) {
$headers = array(); $headers = array();
$headers[] = 'HEAD ' . $request . ' HTTP/1.1'; $headers[] = 'HEAD ' . $request . ' HTTP/1.1';
$headers[] = 'Host: ' . $host; $headers[] = 'Host: ' . $host;
$headers[] = 'Content-Length: 0'; //$headers[] = 'Content-Length: 0';
$headers[] = 'Connection: close'; $headers[] = 'Connection: close';
$headers[] = 'Content-Type: text/html'; $headers[] = 'Content-Type: application/json; charset=utf-8';
$headers = implode("\r\n", $headers) . "\r\n\r\n"; $headers = implode("\r\n", $headers) . "\r\n\r\n";
//send our request //send our request
if (!fwrite($fp, $headers)) { if (!fwrite($fp, $headers)) {
fclose($fp); fclose($fp);
$response = "Could not access webpage specified."; $response = "Hallo.";
} }
else { else {
//read the response //read the response
$rsp = ''; $rsp = '';
while(!feof($fp)) { $rsp .= fgets($fp,8192); } while(!feof($fp)) { $rsp .= fgets($fp,8192); }
fclose($fp); //fclose($fp);
/*
$hunks = explode("\r\n\r\n",trim($rsp)); $hunks = explode("\r\n\r\n",trim($rsp));
$headers = explode("\n", $hunks[count($hunks) - 1]); $headers = explode("\n", $hunks[count($hunks) - 1]);
$response = trim($headers[0]); $response = trim($headers[0]);*/
$response= $rsp;
} }
} }
} }
@ -50,7 +53,7 @@ if(isset($_POST['link'])) {
</head> </head>
<body> <body>
<?php if(isset($response)) { echo $response; } ?> <?php if(isset($response)) { echo $response; } ?>
<form method="post"> <form method="get">
<label for="link">Link</label> <label for="link">Link</label>
<input id="link" type="text" name="link" /> <input id="link" type="text" name="link" />
</form> </form>