iOS NSURLConnection:如何模拟500和404错误?

iOS NSURLConnection: How to simulate 500 and 404 error?

我正在开发一个 iOS,它连接到一个 RESTFUL Web 服务以使用数据。我正在处理 connection: didFailWithError: 委托方法中的错误场景。

最近我才知道,我还需要处理 connection: didReceiveResponse: 委托方法中的一些错误。因为,500 内部错误和 400、404 等错误会在 connection: didReceiveResponse: 中得到通知。

但是,一个问题是我不知道如何测试这些场景。如何重现 500 或 400 个特定错误?对此的任何建议都会对我有很大帮助!!

理解有误请指正

使用此网站调用您可能(可能)需要的每个状态代码http://httpstat.us/

例子: 400 500

响应格式

HTTP/1.1 {status code} {status description}
Content-Type: text/plain
Content-Length: {something}
{any custom response headers}

{status code} {status description}
{list of any custom response headers we added}