STHTTPRequest 和 php 创建自定义错误代码
STHTTPRequest and php create a custom error code
我在我的应用程序中使用 sthttprequest 和 php 进行网络服务器通信。这是一个示例请求:
-(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
}
};
我不想要像 503,500 等已经分配的错误...因为我冒着在没有意义时向用户显示警报的风险。出于实际原因,我想在 completionBlock 中使用块错误而不是简单的字符串。
编辑
我在 Whosebug 中找到了这个答案
所以我可以在数字尚未分配的地方创建自定义错误代码,我必须注意的是 class 数字 4xx 或 5xx。现在我的问题是从 php 页面输出自定义错误代码,如“475”。方法
header_status(475);
不适合我。
这个答案 给我正确的方法 post 自定义错误代码到 sthttprequest 正确识别它。
我在我的应用程序中使用 sthttprequest 和 php 进行网络服务器通信。这是一个示例请求:
-(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
}
};
我不想要像 503,500 等已经分配的错误...因为我冒着在没有意义时向用户显示警报的风险。出于实际原因,我想在 completionBlock 中使用块错误而不是简单的字符串。
编辑
我在 Whosebug 中找到了这个答案
所以我可以在数字尚未分配的地方创建自定义错误代码,我必须注意的是 class 数字 4xx 或 5xx。现在我的问题是从 php 页面输出自定义错误代码,如“475”。方法
header_status(475);
不适合我。
这个答案 给我正确的方法 post 自定义错误代码到 sthttprequest 正确识别它。