postman連接不了localhost問題解決


學習搭建服務器可用postman 連接不了localhost的端口

 

 

網上好多教程是這樣連接

看完視頻后我們是這樣

找了大量資料都解決不了,什么版本,什么證書的都不好使,最簡單的就是去掉http://

 

 

//get 測試

const http=require('http')
const querystring=require('querystring')

const server=http.createServer((req, res)=>{
   
    //GET
    console.log('method',req.method)
    const url=req.url
    //  /
    console.log('url:',url)
    req.query=querystring.parse(url.split('?')[1])
    console.log('query:',req.query)

    res.end(
        JSON.stringify(req.query)
    )

})

server.listen(8000)
console.log('測試get')
node get
const http=require('http')
const server=http.createServer((req, res) =>{
     if(req.method==='POST'){

        console.log('content-type',req.headers['content-type'])

        let postData=""
        req.on('data',chunk=>{
            postData+=chunk.toString()
        })
        req.on('end',()=>{
            console.log(postData)
            res.end('post請求執行結束')
        })
     }
})
server.listen(8000);
console.log('post請求執行開始')
node post

測試代碼

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM