js/jsfun/fnHttp.js HTTP请求
//如果请求的是https,内部会自行加载证书
let url = "https://www.baidu.com"
// let result= fnHttp_get(url)
// console.log(result);
url = "http://localhost:8888/funHttpresponse.html"
let data = {"aaa": "AAA", "id": "123", "price": 12.12,"online":true,"onsale":false}
let resultGet = fnHttp_get(url, data)
console.log("get:",resultGet);
let resultForm = fnHttp_postForm(url, data)
console.log("postForm:", resultForm)
data["obj"]={"title":"bbb","time":fnTime_timestamp()};
let resultPayload=fnHttp_postJSON(url,data)
console.log("postJSON:",resultPayload)
let resultPostTxt=fnHttp_postText(url,JSON.stringify(data))
console.log("postTxt:",resultPostTxt)
let optionGet={"method":"get","timeout":2000,"body":null,"header":{"aa":"aa"},"cookie":{"bb":"bb"}}
console.log("OPTION_GET:", fnHttp_option(url+"?aa=aaa",optionGet))
let optionPostForm={"method":"post","timeout":2000,"body":"aa=aaa&bbb=234&cc=123.123","header":{"Content-Type": "application/x-www-form-urlencoded"},"cookie":{"bb":"bb"}}
console.log("OPTION_POSTFORM:", fnHttp_option(url+"?aa=aaa",optionPostForm))
let optionPostJSON={"method":"post","timeout":2000,"body":JSON.stringify(data),"header":{"Content-Type": "application/json"},"cookie":{"bb":"bb"}}
console.log("OPTION_POSTJSON:", fnHttp_option(url+"?aa=aaa",optionPostJSON))
let optionPostTxt={"method":"post","timeout":2000,"body":"aa=aaa&bbb=234&cc=123.123","header":{"Content-Type": "text/plain"},"cookie":{"bb":"bb"}}
console.log("OPTION_POSTTxt:", fnHttp_option(url+"?aa=aaa",optionPostTxt))
let optionPostBytes={"method":"post","timeout":2000,"body":"aa=aaa&bbb=234&cc=123.123","header":{"Content-Type": "text/plain"},"cookie":{"bb":"bb"}}
console.log("OPTION_POSTBytes:", fnHttp_optionBytes(url+"?aa=aaa",optionPostBytes))
/**
* HTTP操作响应
* @param params
* @jssaas url /funHttpresponse.html
* @jssaas method get,post
* @jssaas timeout 200000
*/
function main_fun_httpresponse(params) {
return fnRenderText(JSON.stringify(params))
}