public ResponseData DownloadResponse(CrawlingOption option) { if (option.Uri.Contains("://docs.google.com")) { return _googleWorker.DownloadResponse(option); } return _worker.DownloadResponse(option); }
private ResponseData GetPostResponseData(WebRequest request, CrawlingOption option) { byte[] byteArray = Encoding.UTF8.GetBytes(option.Data); request.ContentLength = byteArray.Length; // Get the request stream. using (var dataStream = request.GetRequestStream()) { // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); } // Get the response. var response = request.GetResponse(); return GetResponseData((HttpWebResponse)response); }
public ResponseData DownloadResponse(CrawlingOption option) { var request = (HttpWebRequest)WebRequest.Create(new Uri(option.Uri)); _setRequestHeadersStrategy.SetRequestHeaders(request); if (HttpMethod.Get == option.Method) { return GetResponseData((HttpWebResponse)request.GetResponse()); } if (HttpMethod.Post == option.Method) { request.Method = option.Method.ToString().ToUpper(); return GetPostResponseData(request, option); } throw new NotSupportedException(string.Format("Not supported the {0} method", option.Method)); }
public ResponseData DownloadResponse(CrawlingOption option) { var response = _driveService.HttpClient.GetStreamAsync(option.Uri); try { return new ResponseData() { ResponseStream = response.Result, StatusCode = HttpStatusCode.OK, ResponseUri = option.Uri }; } catch (Exception ex) { return new ResponseData() { StatusDescription = ex.ToString() }; } }