/// <summary> /// Process the request. /// </summary> /// <param name="serviceName">The service name to call.</param> /// <param name="query">The query to apply.</param> /// <param name="request">The request.</param> /// <param name="method">The request method.</param> /// <param name="hasAccessToken">Does the request have an access token.</param> /// <returns>The returned type.</returns> private byte[] ProcessRequest(string serviceName, string query, Net.NetRequest request, string method = "GET", bool hasAccessToken = true) { // Construct the URI. Uri constructedServiceUri = new Uri( _serviceRoot.AbsoluteUri.TrimEnd(new char[] { '/' }) + (String.IsNullOrEmpty(serviceName) ? "" : serviceName) + (String.IsNullOrEmpty(query) ? "" : "?" + query.TrimStart(new char[] { '&' }))); // Create the request. request.Method = method; request.AddHeader("Content-Length", (0).ToString()); // If requesting an access token. if (!hasAccessToken) { request.AddHeader("Ocp-Apim-Subscription-Key", _apiKey); if ((_clientIP != null)) { request.AddHeader("X-Search-ClientIP", _clientIP); } if ((_clientID != null)) { request.AddHeader("X-MSEdge-ClientID", _clientID); } if ((_userAgent != null)) { request.AddHeader("User-Agent", _userAgent); } } // Return the result. return(Nequeo.Net.HttpDataClient.Request(constructedServiceUri, request)); }
/// <summary> /// On net context receive handler. /// </summary> /// <param name="sender">The application sender.</param> /// <param name="context">The current net context.</param> private void Client_OnNetContext(object sender, Net.NetContext context) { Net.NetRequest request = null; Net.NetResponse response = null; bool keepAlive = true; bool isError = true; try { string resource = ""; string executionMember = ""; string statusCode = ""; string statusDescription = ""; request = context.NetRequest; response = context.NetResponse; // Get the response headers, and set the response headers. List <NameValue> headers = base.ParseHeaders(response.Input, out resource, base.HeaderTimeout, base.MaximumReadLength); if (headers != null) { // Set the response headers. response.ReadNetResponseHeaders(headers, resource); // Should the connection be kept alive. keepAlive = response.KeepAlive; statusCode = response.StatusCode.ToString(); statusDescription = response.StatusDescription; // Get the execution member. if (!String.IsNullOrEmpty(response.Headers["Member"])) { // Get the execution member. executionMember = response.Headers["Member"].Trim(); switch (executionMember.ToUpper()) { case "OCSP_CS": // CertificateStatus isError = CertificateStatus(response); break; } } else { // Find the response type sent from the server. if (!String.IsNullOrEmpty(response.ContentType)) { // If the response is ocsp. if (response.ContentType.ToLower().Contains("ocsp-response")) { // CertificateStatus isError = CertificateStatus(response); } } } } else { // No headers have been found. keepAlive = false; throw new Exception("No headers have been found."); } // If error. if (isError) { // An internal client error. AnyError(executionMember, statusCode, statusDescription); } } catch (Exception ex) { try { // An internal client error. AnyError("Error", "500", ex.Message); } catch { } } // If keep alive. if (keepAlive) { // Look for a new response if this one has been completed. if (response != null) { try { // If the response stream is active. if (response.Input != null) { // If another response is pending // then start the process again. if (response.Input.Length > 0) { Client_OnNetContext(this, context); } } } catch { } } } }