[英]How can I put a URL in a HTTP request (as the query string)?
我正在使用Node構建一個Webapp,我的服務器需要轉發用戶想要進行的API調用。 基本上,用戶在前端輸入他們要進行的API調用。 然后,應將包含該呼叫詳細信息的請求發送到服務器。
發送信息的最佳方法是什么?
這是一個非常簡單的示例,但是如果您需要更多詳細信息,請告訴我。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script>
function redirect(){
//url you want to encrypt
url = "http://www.test.com";
//url encryption with BTOA function
base64Url = btoa(url)
// Lets Redirect to the new url with URL encrypted
window.location = "http://www.newAddress.com?url="+base64Url
}
</script>
<body>
<a href="#" onclick="redirect()">redirect</a>
</body>
</html>
這將使您通過查詢字符串發送url,另一方面,您只需獲取字符串並對其進行解碼,它是base64。如果您使用的是javascript,則可以使用函數atob()來解碼我們使用btoa或任何其他語言編碼的內容其他base64解碼器(如果您使用其他語言)。
有關更多詳細信息,您可以查看此頁面https://developer.mozilla.org/en/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.