iOS 请求数据 error
解决办法如下:
0x1 ->请求数据时加上缺少的类型
AFHTTPSessionManager *manager = [selfAFHTTPSessionManager];
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager GET:URLString parameters:parameters progress:nilsuccess:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (success) {//并且code = 正确
success(responseObject);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (failure) {
failure(error);
}
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager GET:URLString parameters:parameters progress:nilsuccess:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (success) {//并且code = 正确
success(responseObject);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (failure) {
failure(error);
}
}];
0x2->服务器后台指定数据返回类型
<?php
header("Content-Type:application/json;charset = utf-8");
// 请求--get
// 参数:userName passWord
$userName =
$_GET["userName"];
$passWord =
$_GET["passWord"];
$respond = array("code"=>200,"userName"=>$userName,"title"=>"success");
// 返回结果
echo(json_encode($respond));
// http://127.0.0.1/Login/Login2.php?userName=fa&passWord=123
?>