xamarin - Xamarin 中的 HttpRequestException 状态码
问题描述
该StatusCode
属性已添加到HttpRequestException
.NET 5 中。今天有什么方法可以在 Xamarin 中使用它吗?
解决方案
下面的示例将 HttpWebResponse 返回的状态与 HttpStatusCode 类的成员进行比较,以确定响应的状态。
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
httpReq.AllowAutoRedirect = false;
HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();
if (httpRes.StatusCode==HttpStatusCode.Moved)
{
// Code for moved resources goes here.
}
// Close the response.
httpRes.Close();
推荐阅读
- reactjs - 跨域会话 Cookie(Heroku 上的 Express API + Netlify 上的 React App)
- reactjs - 如何更改 React-i18next 的默认语言?
- woocommerce - 如何在可变产品上使用 Virtual 设置 WooCommere
- android - 在 Mac Os 10.12 中成功安装 Flutter 2。运行颤振医生时,我会崩溃,如图所示。可能是什么问题呢?
- html - 如何使用 OAuth 在 HTML 页面上显示 Discord 名称和个人资料图片?
- c++ - 为什么我的循环总是只运行一次?
- python - 提取彼此相距至少 3 度的点
- c++ - 解决 munmap_chunk(): c++ 中的无效指针错误
- flutter - 使用 VS Code 修改在 localhost 上运行的 Flutter Web 的服务器响应标头
- flutter - 这是我的错误如何解决?当我单击文本字段时出现此错误