Receive custom HTTP statusCode in NSURLConnection sendSynchronousRequest - objective-c

I send a GET request with [NSURLConnection sendSynchronousRequest...] to our web service. The server overrides the default HTTP status codes with his one codes if an error occurred.
I will test the error handling but always become a timeout (Error Domain=NSURLErrorDomain Code=-1001 "The request timed out.") if server send a custom HTTP code. If server sends the standard HTTP code (e.g. 400) the NSURLConnection works correct and gives me this code immediately.
Has anybody used NSURLConnection with NON-Standard HTTP failure codes and can help me to get this setup working?
Thanks

Related

How do you get request error's logs using WizTools REST Client?

I'm making GET and POST requests using WizTools REST Client, but I got HTTP 500 errors. I would like to get logs. Any tips?
HTTP Response
HTTP/1.1 500 Internal Server Error

Writing tests with http request without response

I need to prepare a Java test (citrus framework) which initial step is sending a http request. Unfortunately my app under tests does not reply to this http request with anything while my testing framework expects to have a response and generates an error otherwise. The best way to deal with such a situation which came to my mind is to use some kind of a proxy between my testing framework and actual application which will forward the test request to the actual application and reply back to the testing framework with OK status not waiting for the response from app.
Does it make a sense? How could I prepare such a proxy assuming that my tests are to be running with maven invocation?
I see following options:
Fire and forget: send the Http request (using the fork mode on the send operation in Citrus) and do not care for the response at all. Just leave out the receive message action to ignore the response in Citrus.
Expect the timeout: Send the Http request and use the receive timeout action to verify that the client does not receive a response in the given time
Assert/catch the timeout exception: Use the assert or catch action in Citrus to handle the timeout exception when sending the http request
Personally I would go for the option #2 where you send the Http request and verify that there is no response for a given amount of time. This makes sure that the actual behavior of your application to not send any response does not change over time.

In Angular6, what is the way to simulate receiving 4xx and 5xx responses from server

I am using HttpClient’s post method to send messages to the server. To test it, I want to simulate receiving 404 and 500 responses from the server. What is the way to simulate receiving 4xx and 5xx error messages in Angular6? As far as I know, I cannot use spyOn().and.returnValue because this will not simulate server error and will not trigger the error code handler passes to the post method.

What's the correct HTTP response code to return for Denial of Service (DoS) attack?

I have some logic in the web server to find out if the user is trying to do a DoS attack. But what's the correct HTTP response code to return for that? Also what's a good error message I can put in HTTP body to tell the user politely that he's got into the DoS attack path?
But what's the correct HTTP response code to return for that?
RFC 6585 suggests 429 Too Many Requests
The 429 status code indicates that the user has sent too many requests in a given amount of time ("rate limiting").
If the attack has compromised your ability to handle legitimate requests, then to those you might respond with 503 Service Unavailable.
Note the change in semantics - the person sending the bad requests gets a status out of the 4NN Client Error class, while those not at fault get a status from the 5NN Internal Service Error class.
what's a good error message I can put in HTTP body to tell the user politely that he's got into the DoS attack path?
Please stop that?

HTTP Status Code: 401 in GCMDemo

Reference:http://developer.android.com/google/gcm/demo.html
Server 401 when trying to send a message to my android device.
HTTP Status 500 - HTTP Status Code: 401
type Exception report
message HTTP Status Code: 401
description The server encountered an internal error (HTTP Status Code: 401) that prevented it from fulfilling this request.
exception
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401
com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177)
com.google.android.gcm.server.Sender.send(Sender.java:121)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServ let.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.
Could anybody tell me how to solve?Thank you!
You should take a look at the GCM docs where it explains the GCM response: http://developer.android.com/google/gcm/gcm.html#response and troubleshooting the 401 error code: http://developer.android.com/google/gcm/gcm.html#auth_error
Description from the docs:
Authentication Error
The sender account that you're trying to use to
send a message couldn't be authenticated. Possible causes are:
Authorization header missing or with invalid syntax.
Invalid project number sent as key.
Key valid but with GCM service disabled.
Request originated from a server not whitelisted in the Server Key IPs.
So I would check to make sure that you are setting you authorization header properly and that you Google Project number is properly setup with GCM and accepting your servers IP.