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的更多相关文章
- 解决 android studio 出现:"AndroidStudio:Could not GET 'https://dl.google.com Received status code 400 from server: Bad Request"问题
一.android studio 编译项目时出现"AndroidStudio:Could not GET 'https://dl.google.com Received status cod ...
- Android Studio Gradle build 报错:Received status code 400 from server: Bad Request
错误提示如下 Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/ ...
- Failed to load resource: the server responsed with a status of 400 (Bad Request)
浏览器报错:Failed to load resource: the server responsed with a status of 400 (Bad Request) ajax请求失败,一般情况 ...
- 【解决了一个小问题】gin框架中出现如下错误:"[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 500"
POST到数据到一条gin框架的接口后,客户端收到400错误,并且返回了业务中返回的"decode json fail". 关键代码是: func report(c *gin.Co ...
- HTTP 1.0 Status Code Definitions
part of Hypertext Transfer Protocol -- HTTP/1.1RFC 2616 Fielding, et al. 10 Status Code Definitions ...
- 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() 在请求 ...
- 重定向Http status code 303 和 302
http 302 http 303 Http 302 302是一个普通的重定向代码.直观的看来是,请求者(浏览器或者模拟http请求)发起一个请求,然后服务端重定向到另一个地址.而事实上,服务端仅仅是 ...
- http status code
属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ...
- C#、JAVA操作Hadoop(HDFS、Map/Reduce)真实过程概述。组件、源码下载。无法解决:Response status code does not indicate success: 500。
一.Hadoop环境配置概述 三台虚拟机,操作系统为:Ubuntu 16.04. Hadoop版本:2.7.2 NameNode:192.168.72.132 DataNode:192.168.72. ...
随机推荐
- 清理yum源
最近想在美国VPS上装个Wine 可是在执行yum install wine时却遇到了意想不到的错误 系统提示: You could try using –skip-broken to work ar ...
- eclipse 常见问题及解决
1. Target runtime Apache Tomcat v6.0 is not defined.错误解决方法 原文:http://blog.csdn.net/xw13106209/articl ...
- Objective-c Category使用
Objective-c Category使用 转载:http://blog.csdn.net/lovefqing/article/details/8289851 什么是Category Catego ...
- NSNotificationCenter消息机制的介绍
转载自http://www.cnblogs.com/pengyingh/articles/2367374.html NSNotificationCenter的作用是专门提供程序中不同类之间的消息通讯而 ...
- JAVA异常的捕获与抛出原则
在可能会出现exception的地方,要使用try-catch或者throws或者两者都要.我的判断依据是:如果对可能出现的exception不想被外部(方法的调用者)知道,就在方法内部try-cat ...
- 剑指offer: 38 数字在排序数组中出现的次数
题目描述 统计一个数字在排序数组中出现的次数.例如输入排序数组{1,2,3,3,3,3,4,5} 和数字3,输出4. 思路如下 1. 预估时间复杂度,最复杂情况是,顺序扫描,统计K出现的次数,时间复杂 ...
- 用户输出表单处理php
php中的表单输入处理,我用两个文件,在linux输出: touch php_post1.html php_post1.php php_post1.html代码如下: <!doctype htm ...
- ssh登录很慢解决方法
使用ssh客户端(如:putty)连接Linux服务器,可能会等待10-30秒才有提示输入密码.严重影响工作效率.登录很慢,登录上去后速度正常,这种情况主要有两种可能的原因: 1. DNS反向解析问题 ...
- winform(C#)拖拽实现获得文件路径
设置Form的AllowDrop为true private void Form1_DragDrop(object sender, DragEventArgs e) { ...
- jQuery慢慢啃之特效(八)
1.show([speed,[easing],[fn]])\\显示隐藏的匹配元素 //speed:三种预定速度之一的字符串("slow","normal", o ...