海口建网站公司,深圳网站优化哪家好,seo搜索引擎优化就业前景,软件开发各阶段产生的文档前言
开发过程中使用flurl.http发送http请求#xff0c;但是服务器有时候会返回400、404这样的错误#xff0c;有时候会携带信息#xff0c;比如json提示或者xml或者html的提示#xff0c;一开始不知道怎么捕捉#xff0c;需要结合apipost调试#xff0c;经过百度查找但是服务器有时候会返回400、404这样的错误有时候会携带信息比如json提示或者xml或者html的提示一开始不知道怎么捕捉需要结合apipost调试经过百度查找可以在错误捕获服务器返回的信息
代码
try
{
//http请求
}
catch (FlurlHttpException ex)
{//获取原始字符串支持类型多var errDetail await ex.GetResponseStringAsync();//也可以获取json确定返回json直接转化为对象更合适var statusCode await ex.GetResponseJsonAsyncmyResponse();throw new Exception(errDetail);}参考https://stackoverflow.com/questions/55020852/how-to-handle-bad-request-exception-in-flurl