在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
NetWorkRequest.ts(源代码如下) import * as https from "https"; import * as vscode from 'vscode'; import * as querystring from 'querystring'; export class NetWorkRequest { public static sendRequest(userCode: string) { vscode.window.showInformationMessage("userCode:" + userCode); var userId = userCode; var post_data = { userId: userId } var contents = querystring.stringify(post_data); var options = { hostname: "www.test.com", port: 443, //443 path: "/test-web/api/sysUser/getUserCodeByInfo?" + contents, method: "POST", rejectUnauthorized: false, headers: { Accept: "*/*", "Accept-Encoding": "utf-8", "Accept-Language": "zh-CN,zh;q=0.8", Connection: "keep-alive", Host: "www.test.com" }, }; var mData = ""; var req = https.request(options, function (res) { res.setEncoding('utf-8'); res.on("data", function (d) { var data = JSON.parse(mData+d); console.log("============================================data======================================================:" + data); }); }); // req.write(contents); req.on("error", function (e) { }); req.end(); } } 那么如何调用呢? 调用其实与Java调用很相似,基本上都是类名.方法。 如下调用: import { NetWorkRequest } from './NetWorkRequest'; NetWorkRequest.sendRequest(userCode);
|
请发表评论