Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.php > #4148
| From | Ralph Stahl <post@rstahl.de> |
|---|---|
| Newsgroups | de.comp.lang.php |
| Subject | Re: mit cURL json-Daten an PHP-Script schicken |
| Date | 2017-06-30 13:51 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <oj5do3$pd9$1@dont-email.me> (permalink) |
| References | <oj4vnm$col$1@dont-email.me> <3t59560f76i69fn3e8%sfroehli@Froehlich.Priv.at> |
Stefan Froehlich schrieb:
> On Fri, 30 Jun 2017 09:51:52 Ralph Stahl wrote:
>> Ich bekomme es nicht hin, auswertbare JSON-Daten zu bekommen. Wie
>> müssten sie eigentlich aussehen? So
>>
>> Array
>> (
>> "a" => 5
>> }
>
> Nein, gar nicht. Mit $_POST bekommst Du Daten, die
> x-www-form-urlencoded übertragen worden sind, also grob das, was Dir
> ein HTML-Formular erzeugt.
>
> JSON sieht ganz anders aus, und da es $_JSON in PHP nicht gibt,
> musst Du etwas in der Form von:
>
> #v+
> <?php var_dump(json_decode(file_get_contents("php://input"))); ?>
> #v-
>
> machen.
>
> Servus,
> Stefan
>
Famos! Ich mache jetzt mit deiner obigen Zeile:
<?php
echo 'CMD ' . $_GET['cmd'];
echo "\n";
echo "PARAM\n";
echo var_dump(json_decode(file_get_contents("php://input")));
echo "\n";
und bekomme völlig richtig
[rollo: ~] curl -i -d '{"a":5}' -L http://.../app/getpos
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Fri, 30 Jun 2017 11:44:36 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
CMD getpos
PARAM
object(stdClass)#1 (1) {
["a"]=>
int(5)
}
kann also das entstandene Objekt sinnvoll verwenden. Warum wird dann in
allen möglichen Quellen (Foren, Beispielen) einschließlich der Doku zu
curl der Parameter
curl -H "Content-Type: text/json" ...
als erforderlich bezeichnet?
Danke Stefan!
Ralph
Back to de.comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
mit cURL json-Daten an PHP-Script schicken Ralph Stahl <post@rstahl.de> - 2017-06-30 09:51 +0200
Re: mit cURL json-Daten an PHP-Script schicken Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2017-06-30 08:58 +0000
Re: mit cURL json-Daten an PHP-Script schicken Ralph Stahl <post@rstahl.de> - 2017-06-30 13:51 +0200
Re: mit cURL json-Daten an PHP-Script schicken Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2017-06-30 13:42 +0000
Re: mit cURL json-Daten an PHP-Script schicken Ralph Stahl <post@rstahl.de> - 2017-07-02 16:18 +0200
csiph-web