iOS服务器内部错误 error500具体信息查看

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/a158337/article/details/52167008

在iOS开发过程中,我们有时经常遇到服务器内部连接错误,提示error 500,具体显示就是没有数据返回,相当于网络连接失败。通常的做法是就是用一个NSError捕捉到,然后打印这个error对象,但是事实并不如意,比如:

下面是一个发生错误的error对象的信息:

Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f8398ec9160> { URL: http://app.vyanke.com/vyanke/v2/HS_Chapter?device=ios&ver=1.0&deviceuuid=ED1AEF41-5D7A-4558-AAD8-4B9813EDDAA1-2d67715a60eb4767316e051dab2cf9a23cd71369&timesign=1470755821-561f2a4e7194e3afdc33865e71955d17a2753f97&user=423253-7b9ea28160bd9c9e49d17c90191da805b5fac458&param=%3D%3D%3DHEAD%3D%3D%3DF7Df787M%23W%264%5D%29a%24%24%5DPFMa%27W%26W%29727%3B?%22%3E%22r%2C%22%3B787%27FP727%22%22%3E%22f87oWa%3DFW4%5D%3E?Hm%2Cmi%2C7W%26W%29727iq%5DoMWa%2727%3E787%27F%3D%247P4%23O7877%2CU } { status code: 500, headers {

    Connection = "keep-alive";

    "Content-Type" = "text/html;charset=utf-8";

    Date = "Tue, 09 Aug 2016 15:10:24 GMT";

    "Transfer-Encoding" = Identity;

    "X-Powered-By" = "PHP/5.5.14";

} }, NSErrorFailingURLKey=http://app.vyanke.com/vyanke/v2/HS_Chapter?device=ios&ver=1.0&deviceuuid=ED1AEF41-5D7A-4558-AAD8-4B9813EDDAA1-2d67715a60eb4767316e051dab2cf9a23cd71369&timesign=1470755821-561f2a4e7194e3afdc33865e71955d17a2753f97&user=423253-7b9ea28160bd9c9e49d17c90191da805b5fac458&param=%3D%3D%3DHEAD%3D%3D%3DF7Df787M%23W%264%5D%29a%24%24%5DPFMa%27W%26W%29727%3B?%22%3E%22r%2C%22%3B787%27FP727%22%22%3E%22f87oWa%3DFW4%5D%3E?Hm%2Cmi%2C7W%26W%29727iq%5DoMWa%2727%3E787%27F%3D%247P4%23O7877%2CU, com.alamofire.serialization.response.error.data=<3c21444f 43545950 45206874 6d6c3e0a 3c68746d 6c3e0a3c 68656164 3e0a2020 20203c6d 65746120 63686172 7365743d 22757466 2d38222f 3e0a2020 20203c74 69746c65 3e56e7a0 94e5aea2 41505020 2d204572 726f7220 53697465 3c2f7469 746c653e 0a202020 203c6d65 7461206e 616d653d 22646573 63726970 74696f6e 2220636f 6e74656e 743d2222 2f3e0a20 2020203c 6d657461 206e616d 653d226b 6579776f 72647322 20636f6e 74656e74 3d22222f 3e0a2020 20203c6d 65746120 68747470 2d657175 69763d22 582d5541 2d436f6d 70617469 626c6522 20636f6e 74656e74 3d224945 3d456467 65223e0a 20202020 3c737479 6c652074 7970653d 22746578 742f6373 73223e0a 20202020 20202020 2e636f6e 747b0a20 20202020 20202020 20202062 6f726465 722d7261 64697573 3a203570 783b0a20 20202020 20202020 20202062 61636b67 726f756e 643a2023 66346634 66343b62 6f726465 723a2031 70782073 6f6c6964 20236363 633b0a20 20202020 20202020 20202070 61646469 6e673a32 3070783b 0a202020 20202020 207d0a20 20202020 2020202e 636f6e74 202e636f 64657b20 666f6e74 2d66616d 696c793a 20275469 6d657320 4e657720 526f6d61 6e272c73 616e732d 73657269 663b2066 6f6e742d 73697a65 3a203630 70783b20 636f6c6f 723a2072 65643b0a 20202020 20202020 20202020 6c696e65 2d686569 6768743a 20312e34 3b207061 6464696e 673a2030 3b6d6172 67696e3a 20303b20 70616464 696e672d 6c656674 3a203630 70783b0a 20202020 20202020 20202020 6261636b 67726f75 6e643a20 75726c28 2f767961 6e6b652f 7374796c 65732f63 6c617373 69632f69 6d616765 732f6161 2e6a7067 29206e6f 2d726570 65617420 6c656674 3b7d0a20 20202020 2020202e 636f6e74 202e6465 73637b20 666f6e74 2d73697a 653a2031 3670783b 20666f6e 742d6661 6d696c79 3a20225c 35464145 5c384636 465c3936 43355c39 45443122 2c207361 6e732d73 65726966 3b20636f 6c6f723a 20233333 33343335 3b0a2020 20202020 20202020 20206d61 7267696e 2d626f74 746f6d3a 20323230 70783b7d 0a202020 20202020 202e636f 6e74202e 6c696e6b 207b7465 78742d61 6c69676e 3a206365 6e746572 3b7d0a20 20202020 2020202e 636f6e74 202e6c69 6e6b2061 7b20636f 6c6f723a 20236666 663b2066 6f6e742d 73697a65 3a203136 70783b20 666f6e74 2d66616d 696c793a 20225c35 4641455c 38463646 5c393643 355c3945 4431222c 2073616e 732d7365 7269663b 0a202020 20202020 20202020 64697370 6c61793a 20696e6c 696e652d 626c6f63 6b3b2070 61646469 6e673a35 70782031 3070783b 74657874 2d646563 6f726174 696f6e3a 206e6f6e 653b206c 696e652d 68656967 68743a20 323b2062 61636b67 726f756e 643a2023 30306264 39303b7d 0a202020 20202020 202e636f 6e74202e 6c696e6b 20613a68 6f766572 7b206261 636b6772 6f756e64 3a202330 30626439 303b7d0a 20202020 3c2f7374 796c653e 0a3c2f68 6561643e 0a0a3c62 6f64793e 0a3c6469 7620636c 6173733d 22636f6e 74656e74 223e0a20 2020203c 64697620 636c6173 733d2263 6f6e7422 3e0a2020 20202020 20203c68 3120636c 6173733d 22636f64 65223e0a 20202020 3530303c 2f68313e 0a3c6469 7620636c 6173733d 22646573 63223ee6 9c8de58a a1e599a8 e58685e9 83a8e994 99e8afaf 2e204344 62436f6d 6d616e64 20e697a0 e6b395e6 89a7e8a1 8c205351 4c20e8af ade58fa5 3a205351 4c535441 54455b34 32533032 5d3a2042 61736520 7461626c 65206f72 20766965 77206e6f 7420666f 756e643a 20313134 36205461 626c6520 26233033 393b766b 78642e76 6965775f 73656374 696f6e5f 66696c65 26233033 393b2064 6f65736e 26233033 393b7420 65786973 743c2f64 69763e0a 3c646976 20636c61 73733d22 6c696e6b 223e0a20 2020203c 61206872 65663d22 6a617661 73637269 70743a68 6973746f 72792e62 61636b28 293b223e e8bf94e5 9b9ee4b8 8ae4b880 e9a1b53c 2f613e0a 3c2f6469 763e0a3c 212d2d0a 62617365 50617468 203d202f 6d6e742f 6e66732f 766b6272 6f746865 722e636f 6d2f6170 692f7679 616e6b65 2f70726f 74656374 65640a61 70704964 203d2038 66613636 3865630a 3c627220 2f3e0a3c 623e4e6f 74696365 3c2f623e 3a202055 6e646566 696e6564 20766172 6961626c 653a205f 53455353 494f4e20 696e203c 623e2f6d 6e742f6e 66732f76 6b62726f 74686572 2e636f6d 2f617069 2f767961 6e6b652f 7468656d 65732f63 6c617373 69632f76 69657773 2f657272 6f722f65 72726f72 3530302e 7068703c 2f623e20 6f6e206c 696e6520 3c623e31 323c2f62 3e3c6272 202f3e0a 4e554c4c 2d2d3e20 2020203c 2f646976 3e0a3c2f 6469763e 0a0a3c2f 626f6479 3e0a3c2f 68746d6c 3e0a>, NSLocalizedDescription=Request failed: internal server error (500)}


从这里的信息只可以看到服务器没有返回正确的数据,错误是在服务器内部,也可以看到http响应头信息,其他的貌似就猜不到了,很长一段时间自己都没有注意到这些大量存在的数字,直到今天和同事调试接口的时候,因为确实很多是服务器错误,但是这样根本找不到,不得不想想怎么打印出服务器那个地方错了。自己后来研究了下NSError,发现里面有个字典也许有用。

 NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
        NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"服务器的错误原因:%@",str);

这样就能够打印出具体是服务器那个位置出错了,方便了很多。就可以打印如下具体原因:执行某个SQL语句出错导致的。

<html>
<head>
    <meta charset="utf-8"/>
    <title>V研客APP - Error Site</title>
    <meta name="description" content=""/>
    <meta name="keywords" content=""/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <style type="text/css">
        .cont{
            border-radius: 5px;
            background: #f4f4f4;border: 1px solid #ccc;
            padding:20px;
        }
        .cont .code{ font-family: 'Times New Roman',sans-serif; font-size: 60px; color: red;
            line-height: 1.4; padding: 0;margin: 0; padding-left: 60px;
            background: url(/vyanke/styles/classic/images/aa.jpg) no-repeat left;}
        .cont .desc{ font-size: 16px; font-family: "\5FAE\8F6F\96C5\9ED1", sans-serif; color: #333435;
            margin-bottom: 220px;}
        .cont .link {text-align: center;}
        .cont .link a{ color: #fff; font-size: 16px; font-family: "\5FAE\8F6F\96C5\9ED1", sans-serif;
           display: inline-block; padding:5px 10px;text-decoration: none; line-height: 2; background: #00bd90;}
        .cont .link a:hover{ background: #00bd90;}
    </style>
</head>

<body>
<div class="content">
    <div class="cont">
        <h1 class="code">
    500</h1>
<div class="desc">服务器内部错误. CDbCommand 无法执行 SQL 语句: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'vkxd.view_section_file' doesn't exist</div>
<div class="link">
    <a href="javascript:history.back();">返回上一页</a>
</div>
<!--
basePath = /mnt/nfs/vkbrother.com/api/vyanke/protected
appId = 8fa668ec
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/mnt/nfs/vkbrother.com/api/vyanke/themes/classic/views/error/error500.php</b> on line <b>12</b><br />
NULL-->    </div>
</div>

</body>
</html>




展开阅读全文

没有更多推荐了,返回首页