简体   繁体   English

http post API请求是如何来自我的应用程序的?

[英]How identfy http post API request is from my app?

I run a project which will call API(http post) from my app. 我运行了一个项目,它将从我的应用程序调用API(http post)。 The post data includes the user's profile. 帖子数据包括用户的个人资料。 If the user is valid, he will get a discount coupon. 如果用户有效,他将获得折扣优惠券。 But now, I found if some user calls api from PC (ie. chrome), he will get the coupon too. 但现在,我发现如果一些用户从PC调用api(即chrome),他也会得到优惠券。 We only accept user apply coupon form our app for pushing our app usage. 我们只接受用户申请优惠券形式,以推动我们的应用程序使用。

I know I can set a secret key when my app send a http post. 我知道当我的应用程序发送http帖子时我可以设置一个密钥。 But I think if someone uses sniffer software will find the key and use it. 但我想如果有人使用嗅探器软件会找到密钥并使用它。

So, my question is how to identify this API request is sent from my app. 所以,我的问题是如何识别从我的应用程序发送此API请求。 If not, I will reject this call. 如果没有,我会拒绝这个电话。

You should use https/ssh tunnel and authentication/authorization tokens. 您应该使用https / ssh隧道和身份验证/授权令牌。

So the your keys and tokens are the secrets and https tunnel prevents sniffing 因此,您的密钥和令牌是秘密,https隧道可以防止嗅探

You can try parsing the User-Agent header to help identify the browser being used, version, OS. 您可以尝试解析User-Agent标头,以帮助识别正在使用的浏览器,版本,操作系统。 But you can't be 100% certain. 但你不能100%肯定。

For examples of User Agent strings, see https://deviceatlas.com/blog/list-of-user-agent-strings 有关用户代理字符串的示例,请参阅https://deviceatlas.com/blog/list-of-user-agent-strings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM