2017-05-19 3 views
0

Das ist mein Python (.ipynb) Code:Wie könnte ich ein JSON-Format-Objekt in PHP Echo durch Python in Jupyter Notebook Echo?

import requests 
import json 

url='http://localhost/test.php' 
payload = {'name':'Borja'} 
headers = {'Content-type': 'application/json'} 
r = requests.post(url, data=json.dumps(payload),headers=headers) 
print(r.status_code) 
print(r.headers['Content-Type']) 
print(r.url) 
print(r.encoding) 
print(r.content) 
print(r.text) 

Dies ist der Ausgang des .ipynb: .ipynb output

und das ist mein PHP-Code:

<?php 

$json = file_get_contents("php://input"); 

echo "$json"; 

$json1=json_encode($json); 

echo "<h1>$json1</h1>"; 

?> 

Dies ist Was ich von dem PHP bekomme:

php output

+0

Check [print_r] (http://php.net/manual/en/function.print-r.php) Funktion – MaxZoom

+0

es hat nicht funktioniert ich das gleiche Ergebnis zu erhalten –

+0

was wollen Sie ** ** PHP-Ausgabe zu sein? – rickdenhaan

Antwort

0

Da die HTTP-Methode für die Anforderung POST ist, können Sie das POST-Array direkt codieren.

<?php 

$json = json_encode($_POST); 

echo "<h1>{$json}</h1>"; 

?> 
+0

Ich fürchte, es funktioniert nicht . Das Ergebnis ist [] zwei Klammern. Trotzdem danke! –