- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我们使用javascript的http请求函数:
var request = new XMLHttpRequest();
发送到 https 地址,这会使用任何类型的加密吗?还是 MITM 能够看到我们发送的所有数据?
示例:
function createAuthToken(baseRestURL, callback) {
var APIPath = "account/api/session";
var CORSPath = "https://cors-anywhere.herokuapp.com/";
var completeRestURL = CORSPath + baseRestURL + APIPath;
console.log("REST API URL: " + completeRestURL);
var method = "POST";
var postData = "{\"tokenId\": \"" + document.getElementById('api_key').value + "\",\"secret\": \"" + document.getElementById('secret').value + "\",\"loginMode\": 1,\"applicationType\": 35}";
var async = true;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && (request.status == 200 || request.status == 201)) {
console.log("ONLOAD");
var status = request.status; // HTTP response status, e.g., 200 for "200 OK"
console.log(status);
var response = JSON.parse(request.responseText);
console.log(response.session_token);
return callback(response.session_token);
}
}
request.open(method, completRestURL, async);
request.setRequestHeader("Content-Type", "application/json");
request.setRequestHeader("Accept", "application/json");
request.send(postData);
后续问题:如果没有,是否有办法在我们的客户端 JavaScript 中包含安全的加密?我的想法是在将请求发送到服务器之前使用网站的公钥来加密请求,但我找不到其他人尝试客户端加密。
粗略示例:
var CryptoJS = require("crypto-js");
var stackOverflowKey = "30 82 01 0a 02 82 01..."
var postData = "{\"tokenId\": \"" + document.getElementById('api_key').value + "\",\"secret\": \"" + document.getElementById('secret').value + "\",\"loginMode\": 1,\"applicationType\": 35}";
var encryptedPostData = cryptoJS.hmacSHA256(postData, stackOverflowKey)
//let's skip the callback and request headers as they are the same as above
var request = new XMLHttpRequest();
request.open();
request.send(encryptedPostData);
我没有学习计算机科学,也无法在网上找到任何与此相关的信息。普遍接受的方法是什么?
最佳答案
XMLHttpRequest 中的 HTTP 和 XML 部分一样,只是一个遗留的命名方案。因为所使用的请求不仅可以包含 http 协议(protocol) url,而且接收的也不仅仅是 XML 响应正文。
例如,最初的 W3C 工作草案介绍了 XMLHttpRequest 对象:
https://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/#introduction
The name of the object is XMLHttpRequest for compatibility with the web as it doesn't make much sense otherwise. It supports the transport of other data formats in addition to XML, some implementations support other protocols besides HTTP (that functionality is not covered in this specification though) and the API supports sending data as well.
请注意“一些实现”,因为这是 2006 年的工作草案,因此并非每个人都使用相同的实现。
当前 XMLHttpRequest 的 Whatwg 规范对此名称有这样的规定:
https://xhr.spec.whatwg.org/#introduction
The name XMLHttpRequest is historical and has no bearing on its functionality.
因此,只要所使用的浏览器根据规范实现 XMLHttpRequest,浏览器就会像平常一样处理请求/响应,即对 https 进行加密。
关于javascript - 对 HTTPS 地址的 XMLHTTP POST 请求是否使用任何加密?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51737556/
来自this example的新手ajax问题: 在 xmlhttp.open() 和 xmlhttp.send() 之前如何分配 xmlhttp.responseText ? (如果我们需要demo
有两个progid。我见过两个都用过。 任何人都知道我什么时候应该使用一个,什么时候应该使用另一个? 最佳答案 你绝对不应该使用 Microsoft.XmlHttp。 来自 Microsoft XML
实际上我正在开发一个聊天框......但它不符合这个条件。 这是代码 function submitChat() { if (form1.users.value == "" || form1.me
网络服务器正在返回状态代码和描述以响应 XmlHttp 的请求。成分。来自服务器的实际状态响应开头为: HTTP/1.1 400 Not a valid http POST request 我可以在
我的问题是更多的搜索基础,但是如果我更改 readState 值意味着 4 以外的值会发生什么,如果我更改状态值 200 会发生什么以及为什么这里使用常量值或神奇数字 最佳答案 这不是神奇的数字。 您
我已阅读 the MSDN blog post关于它。 和 this question对我也没有太大帮助。 据我所知,检查 Microsoft.XmlHttp 就足够了。 你能确认一下吗 thisbu
我在我的页面上尝试使用 ajax。但它不起作用,因为 if (xmlhttp.readyState==4 && xmlhttp.status==200) 始终为 false。我已经提醒了 xmlhtt
我正在通过ajax发送电子邮件来联系php。 Php 脚本成功发送电子邮件,但 ajax xmlhttp.readyState 始终返回 2,即使 xmlhttp.status 为 200。 para
我希望这两个对象调用都指向 ActiveXObject。 但是为什么我们要传递两个不同的参数才能在 IE 中工作。 1. Msxml2.XMLHTTP 和 2. 微软.XMLHTTP 他们都一样吗?或
代码如下: url="http://www.csdn.net/" wstr=getHTTPPage(url) start=Newst
我正在编写一组 VBA 宏,其中使用 XMLHTTP 对象向服务器发送异步请求。我发送基本身份验证: XMLHttpReq.setRequestHeader "Authorization","Basi
我正在尝试使用 xmlhttp 和 VBA 抓取网站。 Url 有一个井号 (#) 符号,被 VBA 误解了...... 这与此处解释的问题相同: Error in XMLHTTP Get reque
我当前使用的 xmlhttp 函数正在将一个非常小的 int 传递到 php 文件,以便使用 GET 方法进行处理。 xmlhttp=GetXmlHttpObject(); if (x
我需要严格遵守我的xml文档中元素的顺序。如果我使用 XmlHttpContent 序列化程序来形成 xml 内容,字段将按字母顺序排序。 有没有办法明确指定 xml 中元素的顺序?或者还有其他方法可
我正在尝试使用 javascript 并阅读 from http://search.yahooapis.com/ WebSearchService /V1/webSearch?appid=YahooD
url太长就会提示没有权限,ie8不会,这应该跟浏览器有关的 其实有个问题你注意一下就是,改成POST 方式传就解决了 this.xmlHttp.open("POST", thi
我的 AJAX 不工作,我不知道为什么。我错过了什么?? ReferenceError: xmlhttp 未定义@ javascript.js:5 function insapts(pin){
我有一个从这个 url 获取表格的代码 https://www.reuters.com/companies/AAPL.OQ/financials/income-statement-annual 代码没
我正在尝试让 Excel 从搜索引擎中检索数据 (torrentz.eu/search?q=abc) 它应该获取第一个链接的信息并将其显示在 Excel 上: 单元格 A1:我的查询 单元格 A2:链
我正在尝试使用此代码抓取网站以提取姓名和联系人... Sub Test() Dim htmlDoc As Object Dim htmlDoc2 As Object Di
我是一名优秀的程序员,十分优秀!