http-response-codes

Returning HTTP 401 status for AJAX responses without WWW-Authenticate

a 夏天 提交于 2019-12-09 14:47:49
问题 Is it OK to return an HTTP 401 status for a response to an AJAX call if you wish to convey that the user is not logged in, even though the login mechanism is form-based and not HTTP based (Basic, Digest, etc.)? The answer here suggests that 401 should be used: https://stackoverflow.com/a/6937030/2891365 And this post shows an actual example of someone using 401 for an AJAX response: http://www.bennadel.com/blog/2228-some-thoughts-on-handling-401-unauthorized-errors-with-jquery.htm However,

Why does HttpURLConnection.getResponseCode() throws IOException? [duplicate]

强颜欢笑 提交于 2019-12-07 04:08:23
问题 This question already has answers here : HttpURLConnection.getResponseCode() throws IOException when code is known (2 answers) Closed 3 years ago . I can see that getResponseCode() method is just a getter Method that returns the statusCode already set by the a connect action that happened before. So in this context why does it throw an IOException ? Am i missing something? 回答1: From javadoc: It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e

Why does assigning a value to an unused variable make a difference in the functionality of this async code?

一笑奈何 提交于 2019-12-06 00:07:03
I've got this code: private async Task SavePlatypusComplianceFileOnServer(string year, string month) { string monthAsMM = ReportRunnerConstsAndUtils.GetMonthAsMM(month); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(ReportRunnerConstsAndUtils.SERVER_BASE_ADDRESS); String uriToCall = String.Format("/api/PlatypusCompliance/{0}/{1}{2}", _unit, year, monthAsMM); HttpResponseMessage response = await client.PostAsync(uriToCall, null); } ...that works fine. On looking at it, though, I thought to myself, "Self, why are you assigning a value to "response" when you're not using it?

Why does HttpURLConnection.getResponseCode() throws IOException? [duplicate]

空扰寡人 提交于 2019-12-05 09:13:42
This question already has an answer here: HttpURLConnection.getResponseCode() throws IOException when code is known 2 answers I can see that getResponseCode() method is just a getter Method that returns the statusCode already set by the a connect action that happened before. So in this context why does it throw an IOException ? Am i missing something? From javadoc : It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP). Returns: the HTTP Status-Code, or -1 Throws: IOException - if an error occurred connecting to

How to test render status: 404 with Rails4 and RSpec when using rescue_from

限于喜欢 提交于 2019-12-04 15:50:04
问题 I have a Rails4 application with a 'PagesController'. The show-method throws a customized Exception 'PageNotFoundError' when a Page is not found. On top of the controller I defined rescue_from PageNotFoundError, with: :render_not_found render not found is a private method of PagesController and looks like: def render_not_found flash[:alert]=t(:page_does_not_exists, title: params[:id]) @pages = Page.all render :index, status: :not_found #404 end The rails-log in development-mode shows: Started

What is the correct HTTP status code to send when a site is down for maintenance?

孤者浪人 提交于 2019-12-02 15:01:25
Is there a HTTP status code to tell Google (and others) to go away, index me again later ? Basically, one that semantically tells clients that the site is down for maintenance? The ones I have considered are 304 => Not modified 307 => Temporary redirect 410 => Gone 503 => Service Unavailable I'm leaning towards the last one, but was just curious as to which one was proper choice. Daniel Vassallo HTTP 503 - Service Unavailable would be the most appropriate. The Web server (running the Web site) is currently unable to handle the HTTP request due to a temporary overloading or maintenance of the

How to throw 404 from bean in jsf

大城市里の小女人 提交于 2019-12-02 03:48:15
问题 I need to throw 404 and take visitor to a specific page. I am trying with following code: FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND); externalContext.setResponseHeader(Common.LOCATION, "browse_by_category.xhtml?category=CATEGORY_ALL"); facesContext.responseComplete(); 404 happens but redirection to the browse_by_category.xhtml page does

How to throw 404 from bean in jsf

回眸只為那壹抹淺笑 提交于 2019-12-02 00:49:07
I need to throw 404 and take visitor to a specific page. I am trying with following code: FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND); externalContext.setResponseHeader(Common.LOCATION, "browse_by_category.xhtml?category=CATEGORY_ALL"); facesContext.responseComplete(); 404 happens but redirection to the browse_by_category.xhtml page does not happen. Any help will be greatly appreciated. According to your comment please try this:

Django Testing: See traceback where wrong Response gets created

橙三吉。 提交于 2019-12-02 00:48:53
This pattern is from the django docs: class SimpleTest(unittest.TestCase): def test_details(self): client = Client() response = client.get('/customer/details/') self.assertEqual(response.status_code, 200) From: https://docs.djangoproject.com/en/1.8/topics/testing/tools/#default-test-client If the test fails, the error message does not help very much. For example if the status_code is 302, then I see 302 != 200 . The question is now: Where does the wrong HTTPResponse get created? I would like to see the stacktrace of the interpreter where the wrong HTTPResponse object get created. I read the

REST API response in partial success

a 夏天 提交于 2019-12-01 16:21:38
I have an API which does some bulk processing task. Let's say it does naming of some resource. I passed 7 request in bulk, out of which 5 updated successfully and 2 failed. My question is how to handle the response. With HTTP I can't return both success and error at same time. There is a HTTP code of partial success but I need to return individual response of all resource at once. Is there anyway we can do it? You may use 207 MULTI-STATUS for http status A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate. The