HttpWebRequest.GetResponse() raises exception when http status code 400 (bad request) is returned
参考: .Net HttpWebRequest.GetResponse() raises exception when http status code 400 (bad request) is returned
C# code
using System;
using System.IO;
using System.Net;
public class Test
{
static void Main()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://csharpindepth.com/asd");
try
{
using (Stream data = request.GetResponse().GetResponseStream())
{
using (StreamReader reader = new StreamReader(data))
{
string text = reader.ReadToEnd();
Console.WriteLine(text);
}
}
}
catch (WebException ex)
{
HttpWebResponse response = (HttpWebResponse) ex.response;
Console.WriteLine("Error code: {0}", response.StatusCode);
if (response.StatusCode == HttpStatusCode.BadRequest)
{
using (Stream data = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(data))
{
string text = reader.ReadToEnd();
Console.WriteLine(text);
}
}
}
}
}
}
HttpWebRequest.GetResponse() raises exception when http status code 400 (bad request) is returned相关推荐
- Received status code 400 from server: Bad Request
一.报错信息 FAILURE: Build failed with an exception.* What went wrong: A problem occurred configuring roo ...
- Could not GET “XXXXX.xml”Received status code 400
Could not GET "XXXXX.xml"Received status code 400 from seerver :Bad Request 解决方案如下: **×××确 ...
- Received status code 400 from server: Bad Request解决方案
Received status code 400 from server: Bad Request解决方案 Could not GET ' https://dl.google.com/dl/andro ...
- Request failed with status code 413 AxiosError: Request failed with status code 413 请求体过大报错
在写一个富文本框 内容上传时 由于上传的文件 比如图片文件太大导致发请求的时候 报错413AxiosError: Request failed with status code 请求体过大 这里为了 ...
- nexus上传报Error code 400, Bad Request问题
nexus仓库中默认设置为disable redeploy,不可以重复上传,所以第一次上传成功后,不能接受同名的jar包. 所以,要支持可以重复上传jar,必须在对应的仓库设置allow redepl ...
- vNext中ABP的Exception的Http中的Status Code
对于ABP的文档中的说明,那个httpcode是不一定的,如果你用Volo.Abp.UserFriendlyException他返回的错误也有可能是401 403 500等,这对于前端来说就是个不确定 ...
- System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()
System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse() 在请求 ...
- 服务器如何返回429状态,Instagram远程服务器返回一个错误:(429)UNKNOWN STATUS CODE...
我正在使用我自己的instagram api开发一些新程序. 一切都与我工作正常,除了以下的用户脚本 我想按照我的用户ID 的名单,所以我用这个代码Instagram远程服务器返回一个错误:(429) ...
- 重定向Http status code 303 和 302
http 302 http 303 Http 302 302是一个普通的重定向代码.直观的看来是,请求者(浏览器或者模拟http请求)发起一个请求,然后服务端重定向到另一个地址.而事实上,服务端仅仅是 ...
最新文章
- 轻量级mysql服务_Navicat连接阿里云轻量级应用服务器mysql
- java注释跳转方法,Java自定义注解实现Router跳转
- Java -- 注解 annotation
- python canvas画移动物体_如何实现Canvas图像的拖拽、点击等操作
- C++11 并发指南六(atomic 类型详解三 std::atomic (续))
- (86)FPGA读文件激励(readmemh)
- 跑路后再删库?思科前员工离职后恶意删库,损失达 240 万美元!
- python自学免费教程-python免费入门教程/求完整的Python入门教程
- Redis 3.0正式版发布,正式支持Redis集群
- 医学统计学基础——第一讲
- centos6 系统安装 system-config-kickstart 工具
- Android TV CTS 测试认证汇总
- VSDX Annotator for mac(Visio 绘图工具)
- sql怎么实现2个表连接_多表上SQL连接:概述和实现
- linux系统优化步骤,优化Linux系统的12个步骤
- 发送、抄送、密送、分别发送、回复、回复全部、转发的区别(一篇文章研究透彻)
- 洛谷 P3369 【模板】普通平衡树
- 怎么在视频中截取音频作为手机铃声?
- ResNet详解与分析
- 打造创业团队的执行力