我有一个5角应用程序,我想从中发出一个http请求,它会按以下格式点击一个URL:
https://example.com/api?email={{[email protected]} }&pass={{my密码}}&input = {{user input}}
这会给我一个json的回应。
表单只有一个输入框,用户将填写“用户输入”。除此之外,我需要发送一个硬编码的电子邮件和密码,出于安全目的,我无法保留在客户端。
任何建议如何隐藏它。
首先,您不希望将这些值作为url参数提交,因为它们会在地址栏中公开:
https://example.com/api?email={{[email protected]}}&pass={{my password}}&input={{user input}}
而是像这样对特定端点进行POST或PATCH:
https://example.com/api/user
并将您的数据包含在JSON正文中,例如:
{
"email":"[email protected]",
"pass":"whatever"
"input":"user data"
}
putUserData(body: any){
const headers = new Headers({'Content-Type': 'application/json'});
const options = new RequestOptions({ headers: headers });
const url = 'https://example.com/api/user';
return this._http.patch(url, body, options)
.map((response: Response) => response.json())
}
在调用此端点之前,请先调用另一个端点以获取硬编码的电子邮件和密码,例如:
GET https://example.com/api/user/credentials
这应该提供包含该数据的JSON响应:
{
"email":"[email protected]",
"pass":"whatever"
}
当用户提交表单时,您可以将此对象与表单对象合并。这样,您就不会在客户端上对此数据进行硬编码,也不会将其存储在客户端的任何位置。
但这仍然不是一个安全的解决方案,因为你传递凭据,如果他们足够坚定,黑客就很容易被抓住。