Example #1
0
 private static byte[] GetResponseBody(PortlessWebResponse response)
 {
     using (Stream responseStream = response.GetResponseStream())
     {
         byte[] body = new byte[responseStream.Length];
         responseStream.Read(body, 0, (int)responseStream.Length);
         return(body);
     }
 }
        public async Task HandleRequest(Request request, Func <Error, Response, Task> callback)
        {
            PortlessWebRequest webRequest = host.CreateRequest(request.Url);

            webRequest.Method = request.Method;
            await AddHeaders(request, webRequest);

            AddBody(request, webRequest);
            using (PortlessWebResponse webResponse = webRequest.GetPortlessResponse())
            {
                Response response = new Response();
                response.Url = request.Url;
                AddHeaders(response, webResponse);
                using (Stream stream = webResponse.GetResponseStream())
                {
                    byte[] responseBytes = new byte[stream.Length];
                    stream.Read(responseBytes, 0, (int)stream.Length);
                    response.Body = Encoding.UTF8.GetString(responseBytes);
                }

                await callback(null, response);
            }
        }