/// <summary>
        /// The WriteJsonAsync.
        /// </summary>
        /// <param name="response">The response<see cref="Microsoft.AspNetCore.Http.HttpResponse"/>.</param>
        /// <param name="json">The json<see cref="string"/>.</param>
        /// <param name="contentType">The contentType<see cref="string"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        public static async Task WriteJsonAsync(this Microsoft.AspNetCore.Http.HttpResponse response, string json, string contentType = null)
        {
            response.ContentType = (contentType ?? "application/json; charset=UTF-8");
            await response.WriteAsync(json);

            await response.Body.FlushAsync();
        }
Esempio n. 2
0
        public static void WriteJson <T>(this Microsoft.AspNetCore.Http.HttpResponse response, T obj, string contentType = null)
        {
            response.ContentType = contentType ?? "application/json";

            var json = JsonSerializer.Serialize(obj, obj.GetType());

            response.WriteAsync(json, Encoding.UTF8);
        }
Esempio n. 3
0
        public Task WriteAsync(string messageId, JimuRemoteCallResultData resultMessage)
        {
            _logger.Debug($"finish handling msg: {messageId}");
            var data = _serializer.Serialize <string>(new JimuTransportMsg(messageId, resultMessage));

            //_httpResponse.
            return(_httpResponse.WriteAsync(data));
        }
Esempio n. 4
0
        public async Task LunchPaymentPage(HttpContext httpContext, string authorizationUrl)
        {
            Microsoft.AspNetCore.Http.HttpResponse response = httpContext.Response;
            response.Clear();

            StringBuilder form = new StringBuilder();

            form.Append("<html>");
            form.AppendFormat("<body onload='document.forms[0].submit()'>");
            form.AppendFormat("<form action='{0}' method='post'>", authorizationUrl);
            form.Append("</form>");
            form.Append("</body>");
            form.Append("</html>");

            HasLunchedPaymentPage = true;
            await response.WriteAsync(form.ToString());



            //response.Write(form.ToString());
            //response.End();
        }
Esempio n. 5
0
        public static async Task WriteJsonAsync
        (
            this HttpResponse extended,
            HttpStatusCode statusCode,
            object value,
            JsonSerializerSettings jsonSerializerSettings
        )
        {
            extended.ContentType = "application/json";
            extended.StatusCode  = (int)statusCode;

            var text = JsonConvert.SerializeObject
                       (
                value,
                Formatting.Indented,
                jsonSerializerSettings
                       );

            await extended.WriteAsync
            (
                text,
                Encoding.UTF8
            );
        }
Esempio n. 6
0
 public static async Task WriteHtmlAsync(this HttpResponse response, string html)
 {
     response.ContentType = "text/html; charset=UTF-8";
     await response.WriteAsync(html, Encoding.UTF8);
 }
Esempio n. 7
0
 public static async Task WriteJsonAsync(this HttpResponse response, string json)
 {
     response.ContentType = "application/json; charset=UTF-8";
     await response.WriteAsync(json);
 }
 /// <summary>
 /// 写入自定义对象
 /// </summary>
 /// <param name="response"></param>
 /// <param name="content"></param>
 /// <param name="contentType"></param>
 /// <returns></returns>
 public static async Task WriteCustomContentAsync(this HttpResponse response, object content, string contentType = HttpContentTypeConst.APPLICATION_JSON)
 {
     response.Clear();
     response.ContentType = contentType;
     await response.WriteAsync(JsonConvert.SerializeObject(content));
 }
Esempio n. 9
0
 /// <summary>
 /// Writes SSE event boundary into the stream
 /// </summary>
 /// <param name="response">HttpRepsonse representing the response stream.</param>
 /// <returns>Task to be used to sync execution flow.</returns>
 private static Task WriteSseEventBoundaryAsync(this HttpResponse response)
 {
     return(response.WriteAsync("\n"));
 }
Esempio n. 10
0
 /// <summary>
 /// Writes SSE field data into the stream
 /// </summary>
 /// <param name="response">HttpRepsonse representing the response stream.</param>
 /// <param name="field">String containing a valid SSE field name. See W3C SSE specifications for detail.</param>
 /// <param name="data">String containing the data for this field.</param>
 /// <returns>Task to be used to sync execution flow.</returns>
 private static Task WriteSseEventFieldAsync(this HttpResponse response, string field, string data)
 {
     return(response.WriteAsync($"{field}: {data}\n"));
 }
 public static Task WriteJson <T>(this Microsoft.AspNetCore.Http.HttpResponse response, T obj)
 {
     response.ContentType = "application/json";
     return(response.WriteAsync(Newtonsoft.Json.JsonConvert.SerializeObject(obj)));
 } // End Function MapAny