国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

問一下,android為前端,php為後端的問題
天蓬老師
天蓬老師 2017-05-16 13:07:19
0
6
756

就是http協(xié)議的問題,本人是做後端的,現(xiàn)在和android程式設(shè)計(jì)師發(fā)現(xiàn)了一個(gè)問題,就是他說是已POST請(qǐng)求發(fā)送數(shù)據(jù),但是我php要已json的數(shù)據(jù)類型去接收數(shù)據(jù),但是我在網(wǎng)上看到的人很多都是$_POST[] 這樣獲取數(shù)據(jù),
問題
1.真的要php已json的數(shù)據(jù)類型去接收數(shù)據(jù)那麼php的代碼改怎麼寫
2.他們android是不是有辦法Post請(qǐng)求發(fā)送資料是否可以加name 。就像我們web網(wǎng)站一樣,有個(gè)name。

已使用者名稱 username
密碼 userpass 為範(fàn)例 大家?guī)兔?。謝謝

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進(jìn)步~~

全部回覆(6)
巴扎黑

php接收post的數(shù)據(jù),一般用$_POST可以搞定,如果不行,就用file_get_contents("php://input");

他要求的資料統(tǒng)一用json格式,用PHP處理是很簡(jiǎn)單的,只要用json_decode()解析一下就變成php裡的陣列了。
用戶名密碼之類的變數(shù)都可以包裝在json裡。

phpcn_u1582

1.建議使用下面程式??碼

$c = file_get_contents('php://input');  //解析獲取的二進(jìn)制流 獲取的數(shù)據(jù)格式是json
$j = json_decode($c, true); //解析json數(shù)據(jù),加第二個(gè)參數(shù)true 是數(shù)組 不然是對(duì)象

2.必須可以加

淡淡煙草味

常規(guī)資料用$_POST,XML之類的用file_get_contents('php://input');
不要用$GLOBALS["HTTP_RAW_POST_DATA"],7.0廢棄了。

為情所困

就相當(dāng)於raw

Ty80

這個(gè)問題很好解決,首先post 請(qǐng)求參數(shù)有兩種傳參方式:

  1. form 表單提交

  2. json 格式提交

後端和android 端商量一個(gè)接收資料的方式就行了,沒有作者說的那麼複雜

我想大聲告訴你

樓主用的什麼框架,如果用的laravel或lumen的話直接Request::getContent()接,然後再json_decode()一下。如果要自己實(shí)現(xiàn),可以參考laravel的實(shí)現(xiàn)方式:

public function getContent($asResource = false)
    {
        $currentContentIsResource = is_resource($this->content);
        if (PHP_VERSION_ID < 50600 && false === $this->content) {
            throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
        }

        if (true === $asResource) {
            if ($currentContentIsResource) {
                rewind($this->content);

                return $this->content;
            }

            // Content passed in parameter (test)
            if (is_string($this->content)) {
                $resource = fopen('php://temp', 'r+');
                fwrite($resource, $this->content);
                rewind($resource);

                return $resource;
            }

            $this->content = false;

            return fopen('php://input', 'rb');
        }

        if ($currentContentIsResource) {
            rewind($this->content);

            return stream_get_contents($this->content);
        }

        if (null === $this->content || false === $this->content) {
            $this->content = file_get_contents('php://input');
        }

        return $this->content;
    }
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板