STHTTPRequest和php创建了一个自定义错误代码


STHTTPRequest and php create a custom error code

我在应用程序中使用sthttprequest和php进行Web服务器通信。这是一个示例请求:

-(void)GetSomething:(NSString*)Username :(NSString*)Password {

__block STHTTPRequest *up = [STHTTPRequest requestWithURLString:[NSString stringWithFormat:@"%@%@",PATHSERVER,@"getsomething.php"]];
up.POSTDictionary = @{@"username":Username,@"password":Password};
up.completionBlock = ^(NSDictionary *headers, NSString *body) {

       //my result data


};
up.errorBlock = ^(NSError *error) {
    NSLog(@"-error description and error code- %@", [error localizedDescription]);
};
[up startAsynchronous];
}

当一个条件发生时,我想在我的php页面中输出一个错误,以在sthttprequest错误的块中显示警报:

up.errorBlock = ^(NSError *error) {
NSLog(@"-error description and error code- %@", [error localizedDescription]);
};

是否可以强制php页面中的自定义代码错误来实现这种行为?类似于:

<?php  echo $custom_error_code; ?>
up.errorBlock = ^(NSError *error) {
  if (error.code==1300){
      //this is the code i have set in php
  }
}; 

我不想要像503500这样已经分配好的错误,等等。。。因为我冒着在没有意义的情况下向用户显示警报的风险。出于实际原因,我想在completionBlock中使用块错误,而不是简单的字符串。

编辑

我在stackoverflow找到了这个答案我们可以创建自定义HTTP状态代码吗?

因此,我可以在尚未分配编号的地方创建自定义错误代码,我必须尊重的是类编号4xx或5xx。现在我的问题是从php页面输出一个类似"475"的自定义错误代码。方法

header_status(475);

对我不起作用。

这个答案https://stackoverflow.com/a/23190950/3057259请给我一个正确的方法,将自定义错误代码发布到sthttprequest,以便正确识别它。