視頻教程推薦:node js教程
十多年的海城網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整海城建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“海城網(wǎng)站設(shè)計(jì)”,“海城網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
最近項(xiàng)目需要接口傳輸,于是乎找了那個(gè)選擇哪個(gè)語言,選擇node,而且是https模式!
找了好久才解決跨域問題!廢話不多說,直接上代碼
let mysql = require('mysql'); let express = require('express'); let app = express(); let https = require("https"); let fs = require("fs"); // Configuare https const httpsOption = { key : fs.readFileSync("./https/3_jdong.xuexuebang.cn.key"),//https證書key cert: fs.readFileSync("./https/2_jdong.xuexuebang.cn.crt")//https證書crt } //鏈接數(shù)據(jù)庫 let connection = mysql.createConnection({ host : '127.0.0.1', port : '3306', database : 'sz', user : 'soubei', password : 'soubei', }) connection.connect(); //解決跨域問題 app.all("*",function (req, res, next) { //允許所有請(qǐng)求方式 res.header("Access-Control-Allow-Origin","*");//所有 res.header("Access-Control-Allow-Headers","content-type")//post next() }) app.get('/userlist',function(req,res){ shop_name = req.query.shop_name; connection.query('SELECT * from `order` where orderStatus="暫停" ',function(error,results,fileds){ if(error) throw error; res.header("Access-Control-Allow-Origin", "*"); res.header('Access-Control-Allow-Headers', 'Content-type'); res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS,PATCH"); res.header('Access-Control-Max-Age',1728000);//預(yù)請(qǐng)求緩存20天 res.writeHead(200,{"Content-Type":"text/json;chartset=utf-8"}) data = [] // console.log('SELECT skuId from `cmf_order_sku` where shop_name="'+shop_name+'" group by skuId') connection.query('SELECT skuId from `cmf_order_sku` where shop_name="'+shop_name+'" group by skuId',function(error,result,fileds){ if (result !=''){ res.end(JSON.stringify(result)) } if (error == null){ res.end(JSON.stringify('請(qǐng)求失敗')) } }) }) }) https.createServer(httpsOption, app).listen(8080,function(){ // let host = server.address().address; // let port = server.address().port; console.log("應(yīng)用實(shí)例,運(yùn)行在http://%s:%s") });
效果圖如下
更多編程相關(guān)知識(shí),可訪問:編程教學(xué)??!
網(wǎng)頁題目:nodejs接口如何傳輸數(shù)據(jù)?
本文來源:http://www.rwnh.cn/article36/cpehsg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)站收錄、響應(yīng)式網(wǎng)站、軟件開發(fā)、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)