protected void onPostExecute(String result, Status status, BmobException exception, BmobCallback <T> fCallback) { T data; BmobException ex; if (exception != null) { data = default(T); if (result == null) { ex = exception; } else { ex = new BmobException(exception.Message + ", and response content is " + result, exception.InnerException); } } else { BmobResponseParser <T> parser = getResponseParser(status); parser.parse(result); data = parser.data; ex = parser.exception; } if (ex != null) { BmobDebug.T("[ BmobCommand ] after parse response, error: '" + ex.Message + "'"); } fCallback(data, ex); }
private IEnumerator RequestInternal(String url, String method, byte[] postData, IDictionary <String, String> headers, Action <String, Status, BmobException> callback) { var table = new Dictionary <String, String>(); foreach (var header in headers) { table.Add(header.Key, header.Value); } WWW www = new WWW(url, method.Equals("GET") ? null : postData, table); yield return(www); var error = www.error; var text = www.text; BmobDebug.T("[ BmobUnity ] after fetch www message, Response: '" + text + "', Error: ' " + error + "'"); var status = new Status(200, error); // if (www.responseHeaders.ContainsKey("STATUS")) // { // var respStatus = www.responseHeaders["STATUS"]; // var statusCode = Regex.Replace(respStatus, @"[^ ]* (\d*) .*", "$1"); // status.code = Convert.ToInt32(statusCode); // } try{ if (www.responseHeaders.ContainsKey("STATUS")) { var respStatus = www.responseHeaders["STATUS"]; var statusCode = Regex.Replace(respStatus, @"[^ ]* (\d*) .*", "$1"); status.code = Convert.ToInt32(statusCode); } }catch (NullReferenceException e) { BmobDebug.T("www.responseHeaders方法有问题: " + e); // Unity 2017.2.0f3 (64-bit) 版本,www.responseHeaders方法在真机上有问题。zq,2017.10.24 if (error != null) { foreach (Match match in Regex.Matches(error, @" *(\d*) *")) { status.code = Convert.ToInt32(match.Value); break; } } } if (error != null && error != "") { // 返回了错误的内容,不表示返回的内容就为空!! callback(text, status, new BmobException(error)); } else { callback(text, status, null); } }
protected R Execute <R>(Func <String, String, String, Byte[], IDictionary <String, String>, Action <String, Status, BmobException>, R> request, String url, String contentType, Byte[] postData, IDictionary <String, String> headers, BmobCallback <T> fCallback) { BmobDebug.T("\r\n\t请求的URL : " + url + "\r\n\t交互对象(以请求的数据为准): " + JsonAdapter.JSON.ToRawString(receiver) + "\r\n\t请求的数据: " + JsonAdapter.JSON.ToJsonString(receiver.Data)); return(request.Invoke(url, receiver.Method, contentType, postData, headers, (resp, status, ex) => { if (BmobDebug.Debug) { BmobDebug.D("返回数据内容为: " + resp); } else { var rp = resp.Length > 400 ? resp.Substring(0, 200) + " ... ... ... ... ... ... " + resp.Substring(resp.Length - 200) : resp; BmobDebug.I("返回数据内容为: " + rp); } onPostExecute(resp, status, ex, fCallback); })); }
private IEnumerator RequestInternal(String url, String method, byte[] postData, IDictionary <String, String> headers, Action <String, Status, BmobException> callback) { var table = new Dictionary <String, String>(); foreach (var header in headers) { table.Add(header.Key, header.Value); } #pragma warning disable CS0618 // 类型或成员已过时 WWW www = new WWW(url, method.Equals("GET") ? null : postData, table); #pragma warning restore CS0618 // 类型或成员已过时 yield return(www); var error = www.error; var text = www.text; BmobDebug.T("[ BmobUnity ] after fetch www message, Response: '" + text + "', Error: ' " + error + "'"); var status = new Status(200, error); if (www.responseHeaders.ContainsKey("STATUS")) { var respStatus = www.responseHeaders["STATUS"]; var statusCode = Regex.Replace(respStatus, @"[^ ]* (\d*) .*", "$1"); status.code = Convert.ToInt32(statusCode); } if (error != null && error != "") { // 返回了错误的内容,不表示返回的内容就为空!! callback(text, status, new BmobException(error)); } else { callback(text, status, null); } }