【发布时间】:2021-07-14 09:24:52
【问题描述】:
当我在我的服务器上运行以下代码并单击按钮时,它会将请求发送到我自己的服务器,
这是请求标头
GET /dir/api/blah/confirmation HTTP/1.1
Host: myserver.com
User-Agent: Mozilla/5.0
Content-type: application/x-www-form-urlencoded
Accept: */*
Referer: http://myserver.com/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Connection: close
但我想要发送请求另一个网站,例如example.com/dir/api/blah/confirmation。
我该怎么做?
这是代码
<!DOCTYPE html>
<html>
<body>
<form action="https://example.com" method="POST">
<button type="button" onclick="loadDoc()">Request data</button>
<p id="demo"></p>
<script>
function loadDoc() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML = this.responseText;
}
xhttp.open("GET", "confirmation");
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("fname=Henry&lname=Ford");
}
</script>
</form>
</body>
</html>
【问题讨论】:
标签: javascript html xml header httprequest