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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

老師你好!你沒(méi)有給data賦值,使用http://localhost:8888/blockchain/write?data=hello,傳入值之后,data為空?

package?main

import?(
???"net/http"
???"gocode/BlockChain/core"
???"encoding/json"
???"io"
)

var?blockchain?*core.Blockchain

func?run(){
???//獲取鏈上的數(shù)據(jù)
???http.HandleFunc("/blockchain/get",?blockchainGetHandler)
???//寫數(shù)據(jù)到鏈上
???http.HandleFunc("/blockchain/write",?blockchainWriteHandler)
????//啟動(dòng)對(duì)端口的監(jiān)聽(tīng)
????http.ListenAndServe("localhost:8888",?nil)
????}

//獲取鏈上的數(shù)據(jù)
func?blockchainGetHandler(w?http.ResponseWriter,?r?*http.Request){
???//轉(zhuǎn)化為json數(shù)據(jù)格式
???bytes,?error?:=?json.Marshal(blockchain)
???//如果erroe不為空
???if?error?!=?nil?{
??????http.Error(w,?error.Error(),?http.StatusInternalServerError)
??????return
???}
???io.WriteString(w,?string(bytes))
}

//往區(qū)塊鏈上寫數(shù)據(jù)
func?blockchainWriteHandler(w?http.ResponseWriter,?r?*http.Request){
???blockData?:=?r.URL.Query().Get("data")
???//發(fā)送數(shù)據(jù)
???blockchain.SendData(blockData)
???//把最新的區(qū)塊鏈數(shù)據(jù)會(huì)顯給調(diào)用者
???blockchainGetHandler(w,?r)
}

//啟動(dòng)之后訪問(wèn):?http://localhost:8888/blockchain/get
//添加數(shù)據(jù)到區(qū)塊鏈:?http://localhost:8888/blockchain/write?data=hello?world
func?main()?{
???//創(chuàng)建一個(gè)blockchain
???blockchain?=?core.NewBlockchain()
???run()

}

正在回答

1 回答

這里只是沒(méi)有加校驗(yàn)而已,如果加判斷data沒(méi)有值就會(huì)返回錯(cuò)誤信息

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

霜花似雪 提問(wèn)者

非常感謝!
2018-08-12 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

老師你好!你沒(méi)有給data賦值,使用http://localhost:8888/blockchain/write?data=hello,傳入值之后,data為空?

我要回答 關(guān)注問(wèn)題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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