private void fillResponseValue2Object(HttpWebResponse response, OutputModel target) { int code = Convert.ToInt32(response.StatusCode); Stream receviceStream = response.GetResponseStream(); StreamReader readerOfStream = new StreamReader(receviceStream); string strHTML = readerOfStream.ReadToEnd(); string body = strHTML;//.Replace("\"","");//System.Text.RegularExpressions.Regex.Replace(strHTML,"(?is)(?<=<body>).*(?=</body>)",""); String st = JSONUtil.toJSONObject(""); st = JSONUtil.putJsonData(st, Constant.PARAM_TYPE_BODYINPUTSTREAM, body); if (target != null) { if (!JSONUtil.jsonObjFillValue2Object(st, target)) { try { string responseInfo = body; // Deserialize HTTP response to concrete type. if (!StringUtil.isEmpty(responseInfo)) { JSONUtil.jsonFillValue2Object(responseInfo, target); } } catch (Exception e) { throw new Exception(e.Message); } } WebHeaderCollection responseHeaders = response.Headers; int iHeads = responseHeaders.Count; string headJson = JSONUtil.toJSONObject(""); headJson = JSONUtil.putJsonData(headJson, Constant.QC_CODE_FIELD_NAME, code); for (int i = 0; i < iHeads; i++) { JSONUtil.putJsonData(headJson, responseHeaders.GetKey(i), responseHeaders.GetValues(i)); } JSONUtil.jsonObjFillValue2Object(headJson, target); } }
public static void fillResponseCallbackModel(int code, Object content, OutputModel model) { string errorJson = "{'" + Constant.QC_CODE_FIELD_NAME + "':" + code + ",'" + Constant.QC_MESSAGE_FIELD_NAME + "':'" + content + "'}"; JSONUtil.jsonFillValue2Object(errorJson, model); }