第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

PHP 無法通過 Golang 解壓縮 gzip 數(shù)據(jù)

PHP 無法通過 Golang 解壓縮 gzip 數(shù)據(jù)

Go
紅顏莎娜 2021-10-25 19:56:44
為什么在我的 PHP 演示中無法通過 Go 解壓 gzip 數(shù)據(jù),但是 PHP gzip data to Go 卻成功了?我需要從 Go to PHP API 服務(wù)發(fā)布 gzip JSON 數(shù)據(jù)。測試結(jié)果 -> |  php   |  go ---------------------php |  ok    |  okgo  |  fail  |  okPHP代碼class GzipDemo{    public function gzen($data, $file){       $json_data = json_encode($data);       $gz_data = gzencode($json_data,9);       file_put_contents($file,$gz_data);    }    public function gzdn($file){       $data = file_get_contents($file);        $unpacked = gzdecode($data);        if ($unpacked === FALSE)        {            print("failed:".$file."\n");        }else{             print($file. " result Data :".$unpacked ."\n");        }    }}$demo = new GzipDemo();$file="phpgzip.txt";$demo->gzen("data",$file);$demo->gzdn($file);$demo->gzdn("gogzip.txt");這樣的結(jié)果:PHP 到 PHP 還行。轉(zhuǎn)到 PHP 失敗。去代碼package mainimport (    "bytes"    "compress/gzip"    "encoding/json"    "fmt"    "io/ioutil"    "os")func main() {    gzen("data", "gogzip.txt")    gden("gogzip.txt")    gden("phpgzip.txt")}func gzen(data string, file string) {    b, _ := json.Marshal(data)    buffer := new(bytes.Buffer)    w, _ := gzip.NewWriterLevel(buffer, gzip.BestCompression)    defer w.Close()    w.Write(b)    w.Flush()    ioutil.WriteFile(file, buffer.Bytes(), os.ModePerm)}func gden(file string) {    b, _ := ioutil.ReadFile(file)    buffer := new(bytes.Buffer)    buffer.Write(b)    r, _ := gzip.NewReader(buffer)    defer r.close()    data, _ := ioutil.ReadAll(r)    fmt.Println(file, " result Data:", string(data))}這個(gè)結(jié)果:Go to Go就可以了。PHP 去就好了。
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 259 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)