http-status-codes

Returning http status code from Web Api controller

我怕爱的太早我们不能终老 提交于 2019-11-26 08:54:58
问题 I\'m trying to return a status code of 304 not modified for a GET method in a web api controller. The only way I succeeded was something like this: public class TryController : ApiController { public User GetUser(int userId, DateTime lastModifiedAtClient) { var user = new DataEntities().Users.First(p => p.Id == userId); if (user.LastModified <= lastModifiedAtClient) { throw new HttpResponseException(HttpStatusCode.NotModified); } return user; } } The problem here is that it\'s not an

curl and ping - how to check whether a website is either up or down?

别来无恙 提交于 2019-11-26 08:25:36
问题 I want to check whether a website is up or down at a particular instance using PHP. I came to know that curl will fetch the contents of the file but I don\'t want to read the content of the website. I just want to check the status of the website. Is there any way to check the status of the site? Can we use ping to check the status? It is sufficient for me to get the status signals like (404, 403, etc) from the server. A small snippet of code might help me a lot. 回答1: something like this

HTTP status code 0 - Error Domain=NSURLErrorDomain?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 08:09:54
问题 I am working on an iOS project. In this application, I am downloading images from the server. Problem: While downloading images I am getting Request Timeout. According to documentation HTTP status code of request timeout is 408 . But in my application, I am getting HTTP status code 0 with the following error Error Domain=NSURLErrorDomain Code=-1001 \"The request timed out.\" UserInfo=0xb9af710 {NSErrorFailingURLStringKey= http://xxxx.com/resources/p/PNG/1383906967_5621_63.jpg ,

How do I get the HTTP status code with jQuery?

[亡魂溺海] 提交于 2019-11-26 08:05:23
问题 I want to check if a page returns the status code 401. Is this possible? Here is my try, but it only returns 0. $.ajax({ url: \"http://my-ip/test/test.php\", data: {}, complete: function(xhr, statusText){ alert(xhr.status); } }); 回答1: this is possible with jQuery $.ajax() method $.ajax(serverUrl, { type: OutageViewModel.Id() == 0 ? "POST" : "PUT", data: dataToSave, statusCode: { 200: function (response) { alert('1'); AfterSavedAll(); }, 201: function (response) { alert('1'); AfterSavedAll();

Android: How get the status-code of an HttpClient request

蹲街弑〆低调 提交于 2019-11-26 08:02:45
问题 I want to download a file and need to check the response status code (ie HTTP /1.1 200 OK ). This is a snipped of my code: HttpGet httpRequest = new HttpGet(myUri); HttpEntity httpEntity = null; HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(httpRequest); ... How do i get the status-code of the response? 回答1: This will return the int value: response.getStatusLine().getStatusCode() 回答2: if (response.getStatusLine().getStatusCode()==

How can I get the HTTP status code out of a ServletResponse in a ServletFilter?

北城以北 提交于 2019-11-26 08:02:13
问题 I\'m trying to report on every HTTP status code returned from my webapp. However the status code does not appear to be accessible via the ServletResponse, or even if I cast it to a HttpServletResponse. Is there a way to get access to this value within a ServletFilter? 回答1: First, you need to save the status code in an accessible place. The best to wrap the response with your implementation and keep it there: public class StatusExposingServletResponse extends HttpServletResponseWrapper {

What&#39;s the difference between HTTP 301 and 308 status codes?

怎甘沉沦 提交于 2019-11-26 07:57:27
问题 What\'s the difference between HTTP 301 and 308 status codes? 301 (Moved Permanently): This and all future requests should be directed to the given URI. 308 (Permanent Redirect): The request and all future requests should be repeated using another URI. They seem to be similar. 回答1: An overview of 301 , 302 and 307 The RFC 7231, the current reference for semantics and content of the HTTP/1.1 protocol, defines the 301 (Moved Permanently) and 302 (Found) status code, that allows the request

Set Response Status Code [duplicate]

陌路散爱 提交于 2019-11-26 07:28:58
问题 This question already has an answer here: PHP: How to send HTTP response code? 8 answers I have an API call for which I need to be able to run some checks and potentially return various status codes. I don\'t need custom views or anything, I just need to return the proper code. If the user hasn\'t passed proper credentials, I need to return a 401 status. If they haven\'t sent a supported request format, I need to return a 400 status. Because it\'s an API, all I really want to do is set the

What is the difference between HTTP status code 200 (cache) vs status code 304?

。_饼干妹妹 提交于 2019-11-26 05:49:31
I'm using the Google "Page Speed" plug-in for Firefox to access my web site. Some of the components on my page is indicated as HTTP status: 200 200 (cache) 304 By Google's "Page Speed". What I'm confused about is the difference between 200 (cache) and 304. I've refreshed the page multiple times (but have not cleared my cache) and it always seems that my favicon.ico and a few images are status=200 (cache) while some other images are http status 304. I don't understand why the difference. UPDATE : Using Google "Page Speed", I receive a "200 (cache)" for http://example.com/favicon.ico as well as

Throw HttpResponseException or return Request.CreateErrorResponse?

落花浮王杯 提交于 2019-11-26 04:57:30
问题 After reviewing an article Exception Handling in ASP.NET Web API I am a bit confused as to when to throw an exception vs return an error response. I am also left wondering whether it is possible to modify the response when your method returns a domain specific model instead of HttpResponseMessage ... So, to recap here are my questions followed by some code with case #s: Questions Questions regarding Case #1 Should I always use HttpResponseMessage instead of a concrete domain model, so that