创建一个根据客户端设备发送数据的API [英] Make an API that sends the data depending upon client device

查看:113
本文介绍了创建一个根据客户端设备发送数据的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,
 
I want my WEBAPI to send data in JSON Format when it receives the request from a Desktop Application and XML Format when it receives the request from a Mobile Application

How do I do that ?





我尝试了什么:



尝试谷歌搜索但没有找到任何特定的



What I have tried:

Tried Googling but didnt find anything specific

推荐答案

依靠你的webapi版本尝试采取客户端设计在您的控制器中来自Request对象或http请求对象。

for .netcore2.1从此对象获取设备:Request.Headers [User-Agent]

检查转换为字符串的对象内的项是否包含android或IOS。

您可以在此对象中检索很多关于客户端的信息
Depend on version of your webapi try take the client devise in your controller from Request object or http request object .
for .netcore2.1 take the device from this object: Request.Headers["User-Agent"]
check if items inside the object converted to string contains android or IOS .
you can retrieve a lot about client in this object


这篇关于创建一个根据客户端设备发送数据的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆