working on it ...

Filters

Explore Public Snippets

Sort by

Found 3,477 snippets matching: proxy

    public by RomanKhachko  227154  10  4  2

    Proxy via WebDriver

    String proxyIpAddress= "any_IP_address_of_proxy_server";
    Proxy proxy = new Proxy();
    proxy.setHttpProxy(proxyIpAddress);
    proxy.setSslProxy(proxyIpAddress);
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, proxy);
    WebDriver driver = new ChromeDriver(capabilities);
    

    public by cghersi  3026  0  6  0

    How to create a DefaultHttpClient with proxy settings

    This is how to create a DefaultHttpClient adding information regarding the proxy the client is using
    private static DefaultHttpClient createHttpClient() {
    	DefaultHttpClient httpClient = new DefaultHttpClient();
    	if (!Utils.isNullOrEmpty(proxyAddress) && (proxyPort > 0)) {
    		HttpHost httpproxy = new HttpHost(proxyAddress, proxyPort);
    		httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpproxy);
    	}
    	return httpClient;
    }

    public by cghersi  2643  1  7  0

    How to retrieve proxy settings within Eclipse

    This class helps to retrieve the proxy settings stored in the preferences of Eclipse. It automatically retrieves such settings using an IProxyService instance provided by the Eclipse RCP platform.
    public class ProxyManager {
    	
    	private final static ServiceTracker<IProxyService, IProxyService> proxyTracker;
    	protected static Logger log = Logger.getLogger(ProxyManager.class);
    	
    	static {
    		proxyTracker = new ServiceTracker<IProxyService, IProxyService>(FrameworkUtil.getBundle(ProxyManager.class).getBundleContext(), 
    				IProxyService.class.getName(), null);
            proxyTracker.open();
    	}
    	
    	private static IProxyService getProxyService() {
            return proxyTracker.getService();
        }
    	
    	public static void setProxy() {
    		IProxyService proxyService = getProxyService();
            IProxyData[] proxyDataForHost = null;
    		try {
    			proxyDataForHost = proxyService.select(new URI(AppConfig.get().getSiteBasePath()));
    		} catch (URISyntaxException e) {
    			log.error("CAnnot find url for proxy service due to " + e, e);
    			return;
    		}
    
    		if (proxyDataForHost != null) {
    	        for (IProxyData data : proxyDataForHost) {
    	            if (data.getHost() != null) {
    	                WebConnector.setProxySettings(data.getHost(), data.getPort());
    	            }
    	        }
    		}
    		
            // Close the service and close the service tracker
            proxyService = null;
    	}
    }

    public by PRDeltoid  1462  0  3  0

    PHP Proxy

    PHP Proxy: gistfile1.txt
    PHP
    <?php
        define('WP_USE_THEMES', false);
        require('../../../wp-blog-header.php');
        if(!isset($_GET)) {
            echo "Get not set";
        } else {
            if(isset($_GET['type'])) {
                $type = $_GET['type'];
                if($_GET['type']=="dog") {
                    header('Content-type: application/json');
                    $xml_string = file_get_contents('http://www.petango.com/...');
                    $xml = simplexml_load_string($xml_string);
                    $json = json_encode($xml);
                    echo $json;
                } else if($_GET['type']=="cat") {
                    header('Content-type: application/json');
                    $xml_string = file_get_contents('http://www.petango.com...');
                    $xml = simplexml_load_string($xml_string);
                    $json = json_encode($xml);
                    echo $json;
                } else {
                    echo "Unknown type set";
                }
            } else {
                echo "No type set";
            }
        }
    ?>
    
    
    

    public by muhafazakar  1316  0  4  0

    Nginx block unwanted open proxy, allow only POST, GET HEAD methods, No iframe embed - istenmedik acik proxy yi bloke et ve sadece POST GET HEAD methodlarine izin ver Iframe yerlestirmeyi yasakla

    Nginx block unwanted open proxy, allow only POST, GET HEAD methods, No iframe embed - istenmedik acik proxy yi bloke et ve sadece POST GET HEAD methodlarine izin ver Iframe yerlestirmeyi yasakla: Nginx block unwanted open proxy - istenmedik acik proxy yi bloke et
    http{
    ...
         #hide server version 
         server_tokens off;
         
        # config to don't allow the browser to render the page inside an frame or iframe
        add_header X-Frame-Options SAMEORIGIN;
    
        server {
            listen       80;
            server_name  localhost;
            return 444;
            break;
    
            location / {
              # in every server block that contain location paste this
              if ($request_method !~ ^(GET|HEAD|POST)$ ){
                      return 444;
              }
            }
        }
    ...
      include "/usr/localvirtual/*.conf"
    }
    
    

    public by msdn  222222  0  6  0

    Main: This sample uses the ProxyCommand class to create a proxy command that calls an existing cmdlet, but restricts the set of available parameters. The proxy command is then added to an intial session state that is used to crea...

    This sample uses the ProxyCommand class to create a proxy command that calls an existing cmdlet, but restricts the set of available parameters. The proxy command is then added to an intial session state that is used to create a contrained runspace. This means that the user can access the cmdlet through the proxy command. This sample
    /// <summary>
    /// This sample uses the ProxyCommand class to create a proxy command that 
    /// calls an existing cmdlet, but restricts the set of available parameters.  
    /// The proxy command is then added to an intial session state that is used to 
    /// create a contrained runspace. This means that the user can access the cmdlet 
    /// through the proxy command.
    /// </summary>
    /// <remarks>
    /// This sample demonstrates the following:
    /// 1. Creating a CommandMetadata object that describes the metadata of an 
    ///    existing cmdlet.
    /// 2. Modifying the cmdlet metadata to remove a parameter of the cmdlet.
    /// 3. Adding the cmdlet to an initial session state and making it private.
    /// 4. Creating a proxy function that calls the existing cmdlet, but exposes 
    ///    only a restricted set of parameters.   
    /// 6. Adding the proxy function to the initial session state. 
    /// 7. Calling the private cmdlet and the proxy function to demonstrate the 
    ///    constrained runspace.
    /// </remarks>
    private static void Main()
    {
      // Create a default intial session state. The default inital session state
      // includes all the elements that are provided by Windows PowerShell. 
      InitialSessionState iss = InitialSessionState.CreateDefault();
          
      // Add the get-proc cmdlet to the initial session state.
      SessionStateCmdletEntry cmdletEntry = new SessionStateCmdletEntry("get-proc", typeof(GetProcCommand), null);
      iss.Commands.Add(cmdletEntry);
          
      // Make the cmdlet private so that it is not accessable.
      cmdletEntry.Visibility = SessionStateEntryVisibility.Private;
          
      // Set the language mode of the intial session state to NoLanguge to 
      //prevent users from using language features. Only the invocation of 
      // public commands is allowed.
      iss.LanguageMode = PSLanguageMode.NoLanguage;
          
      // Create the proxy command using cmdlet metadata to expose the 
      // get-proc cmdlet.
      CommandMetadata cmdletMetadata = new CommandMetadata(typeof(GetProcCommand));
          
      // Remove one of the parameters from the command metadata.
      cmdletMetadata.Parameters.Remove("Name");
          
      // Generate the body of a proxy function that calls the original cmdlet, 
      // but does not have the removed parameter.
      string bodyOfProxyFunction = ProxyCommand.Create(cmdletMetadata);
          
      // Add the proxy function to the initial session state. The name of the proxy 
      // function can be the same as the name of the cmdlet, but to clearly 
      // demonstrate that the original cmdlet is not available a different name is 
      // used for the proxy function.
      iss.Commands.Add(new SessionStateFunctionEntry("get-procProxy", bodyOfProxyFunction));
          
      // Create the constrained runspace using the intial session state. 
      using (Runspace myRunspace = RunspaceFactory.CreateRunspace(iss))
      {
        myRunspace.Open();
            
        // Call the private cmdlet to demonstrate that it is not available.
        try
        {
          using (PowerShell powershell = PowerShell.Create())
          {
            powershell.Runspace = myRunspace;
            powershell.AddCommand("get-proc").AddParameter("Name", "*explore*");
            powershell.Invoke();
          }
        }
        catch (CommandNotFoundException e)
        {
          System.Console.WriteLine(
                        "Invoking 'get-proc' failed as expected: {0}: {1}", 
                        e.GetType().FullName, 
                        e.Message);
        }
            
        // Call the proxy function to demonstrate that the -Name parameter is 
        // not available.
        try
        {
          using (PowerShell powershell = PowerShell.Create())
          {
            powershell.Runspace = myRunspace;
            powershell.AddCommand("get-procProxy").AddParameter("Name", "idle");
            powershell.Invoke();
          }
        }
        catch (ParameterBindingException e)
        {
          System.Console.WriteLine(
                        "\nInvoking 'get-procProxy -Name idle' failed as expected: {0}: {1}", 
                        e.GetType().FullName, 
                        e.Message);
        }
            
        // Call the proxy function to demonstrate that it calls into the 
        // private cmdlet to retrieve the processes.
        using (PowerShell powershell = PowerShell.Create())
        {
          powershell.Runspace = myRunspace;
          powershell.AddCommand("get-procProxy");
          List<Process> processes = new List<Process>(powershell.Invoke<Process>());
          System.Console.WriteLine(
                        "\nInvoking the get-procProxy function called into the get-proc cmdlet and returned {0} processes", 
                        processes.Count);
        }
            
        // Close the runspace to release resources.
        myRunspace.Close();
      }
          
      System.Console.WriteLine("Hit any key to exit...");
      System.Console.ReadKey();
    }

    public by msdn  90808  0  6  0

    GenerateIPRange: Generate an IP range based on IP address of the user's machine. due to potential existence of proxy servers between the client and Azure, instead of using the address we are accessing Azure with currently we gener...

    Generate an IP range based on IP address of the user's machine. due to potential existence of proxy servers between the client and Azure, instead of using the address we are accessing Azure with currently we generate a range from ***.***.0.0 to ***.***.255.255 so the connection from the client to the database can be re-routed to any of the
    using System;
    using Microsoft.Win32;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.IO;
    using System.Diagnostics;
    
    /// <summary>
    /// Generate an IP range based on IP address of the user's machine. 
    /// due to potential existence of proxy servers between the client and Azure, instead of using
    /// the address we are accessing Azure with currently we generate a range from ***.***.0.0 to 
    /// ***.***.255.255 so the connection from the client to the database can be re-routed to any 
    /// of the proxy servers without the firewall failing the new connection. The range could be smaller
    /// if the addresses of the proxy servers are known.
    /// </summary>
    /// <param name="localIP">IP address return by AzureManagementbroker.CreateFirewallRuleWithIPDetect </param>
    /// <returns>two IPs as shown in the summary</returns>
    private static string[] GenerateIPRange(string localIP)
    {
        string[] IPBytes = localIP.Split('.');
    
        string[] IPRange = new string[2];
    
        IPRange[0] = IPBytes[0] + "." + IPBytes[1] + "." + "0" + "." + "0";
        IPRange[1] = IPBytes[0] + "." + IPBytes[1] + "." + "255" + "." + "255";
    
        return IPRange;
    }

    public by msdn  2361  1  7  0

    Create: Creates an OperationContextScope for a provided web service proxy It inserts some authentication metadata within the header of each outgoing request

    Creates an OperationContextScope for a provided web service proxy It inserts some authentication metadata within the header of each outgoing request
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    
    /// <summary>
    /// Creates an OperationContextScope for a provided web service proxy
    /// It inserts some authentication metadata within the header of each outgoing request
    /// </summary>
    public static OperationContextScope Create<TChannel>(ClientBase<TChannel> client) where TChannel : class
    {
        OperationContextScope scope =
            new OperationContextScope((IContextChannel)client.InnerChannel);
        MessageHeaders messageHeadersElement =
          OperationContext.Current.OutgoingMessageHeaders;
        messageHeadersElement.Clear();
        messageHeadersElement.Add(
           MessageHeader.CreateHeader("username", "", Globals.UserName));
        messageHeadersElement.Add(
           MessageHeader.CreateHeader("password", "", Globals.Password));
    
        return scope;
    }

    public by msdn  1936  0  6  0

    GetDevelopmentStorageAccount: Returns a <see cref="CloudStorageAccount"/> with development storage credentials using the specified proxy Uri.

    Returns a with development storage credentials using the specified proxy Uri. The proxy endpoint to use. The new .
    /// <summary>
    /// Gets a <see cref="CloudStorageAccount"/> object that references the development storage account.
    /// </summary>
    /// <value>A reference to the development storage account.</value>
    public static CloudStorageAccount DevelopmentStorageAccount
            {
                get
                {
                    if (devStoreAccount == null)
                    {
                        devStoreAccount = GetDevelopmentStorageAccount(new Uri("http://127.0.0.1"));
                    }
    
                    return devStoreAccount;
                }
            }
    /// <summary>
    /// The default account name for the development storage.
    /// </summary>
    private const string DevstoreAccountSettingString = "devstoreaccount1";
    /// <summary>
    /// The default account key for the development storage.
    /// </summary>
    private const string DevstoreAccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
    
    /// <summary>
    /// Returns a <see cref="CloudStorageAccount"/> with development storage credentials using the specified proxy Uri.
    /// </summary>
    /// <param name="proxyUri">The proxy endpoint to use.</param>
    /// <returns>The new <see cref="CloudStorageAccount"/>.</returns>
    internal static CloudStorageAccount GetDevelopmentStorageAccount(Uri proxyUri)
    {
        if (proxyUri == null)
        {
            return DevelopmentStorageAccount;
        }
    
        string prefix = proxyUri.Scheme + "://" + proxyUri.Host;
    
        return new CloudStorageAccount(
            new StorageCredentialsAccountAndKey(DevstoreAccountSettingString, DevstoreAccountKey),
            new Uri(prefix + ":10000/devstoreaccount1"),
            new Uri(prefix + ":10001/devstoreaccount1"),
            new Uri(prefix + ":10002/devstoreaccount1"));
    }

    public by msdn  1583  0  7  0

    GetProxy: Generic method to obtain discovery/organization service proxy instance.

    Generic method to obtain discovery/organization service proxy instance. Set IDiscoveryService or IOrganizationService type to request respective service proxy instance. Set the return type to either DiscoveryServiceProxy or OrganizationServiceProxy type based on TService type. An instance of existing Configuration An instance of
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.DirectoryServices.AccountManagement;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    using System.Text;
    using System.Xml;
    using System.Xml.Linq;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Client;
    using Microsoft.Xrm.Sdk.Discovery;
    using Microsoft.Crm.Services.Utility;
    
    /// <summary>
    /// Generic method to obtain discovery/organization service proxy instance.
    /// </summary>
    /// <typeparam name="TService">
    /// Set IDiscoveryService or IOrganizationService type 
    /// to request respective service proxy instance.
    /// </typeparam>
    /// <typeparam name="TProxy">
    /// Set the return type to either DiscoveryServiceProxy 
    /// or OrganizationServiceProxy type based on TService type.
    /// </typeparam>
    /// <param name="currentConfig">An instance of existing Configuration</param>
    /// <returns>An instance of TProxy 
    /// i.e. DiscoveryServiceProxy or OrganizationServiceProxy</returns>
    public static TProxy GetProxy<TService, TProxy>(ServerConnection.Configuration currentConfig)
        where TService : class
        where TProxy : ServiceProxy<TService>
    {
        // Check if it is organization service proxy request.
        Boolean isOrgServiceRequest = typeof(TService).Equals(typeof(IOrganizationService));
    
        // Get appropriate Uri from Configuration.
        Uri serviceUri = isOrgServiceRequest ?
            currentConfig.OrganizationUri : currentConfig.DiscoveryUri;
    
        // Set service management for either organization service Uri or discovery service Uri.
        // For organization service Uri, if service management exists 
        // then use it from cache. Otherwise create new service management for current organization.
        IServiceManagement<TService> serviceManagement =
            (isOrgServiceRequest && null != currentConfig.OrganizationServiceManagement) ?
            (IServiceManagement<TService>)currentConfig.OrganizationServiceManagement :
            ServiceConfigurationFactory.CreateManagement<TService>(
            serviceUri);
    
        if (isOrgServiceRequest)
        {
            if (currentConfig.OrganizationTokenResponse == null)
            {
                currentConfig.OrganizationServiceManagement =
                    (IServiceManagement<IOrganizationService>)serviceManagement;
            }
        }
        // Set the EndpointType in the current Configuration object 
        // while adding new configuration using discovery service proxy.
        else
        {
            // Get the EndpointType.
            currentConfig.EndpointType = serviceManagement.AuthenticationType;
            // Get the logon credentials.
            currentConfig.Credentials = GetUserLogonCredentials(currentConfig);
        }
    
        // Set the credentials.
        AuthenticationCredentials authCredentials = new AuthenticationCredentials();
    
        // If UserPrincipalName exists, use it. Otherwise, set the logon credentials from the configuration.
        if (!String.IsNullOrWhiteSpace(currentConfig.UserPrincipalName))
        {
            // Single sing-on with the Federated Identity organization using current UserPrinicipalName.
            authCredentials.UserPrincipalName = currentConfig.UserPrincipalName;
        }
        else
        {
            authCredentials.ClientCredentials = currentConfig.Credentials;
        }
    
        Type classType;
    
        // Obtain discovery/organization service proxy for Federated,
        // Microsoft account and OnlineFederated environments. 
        if (currentConfig.EndpointType !=
            AuthenticationProviderType.ActiveDirectory)
        {
            if (currentConfig.EndpointType == AuthenticationProviderType.LiveId)
            {
                authCredentials.SupportingCredentials = new AuthenticationCredentials();
                authCredentials.SupportingCredentials.ClientCredentials =
                    currentConfig.DeviceCredentials;
            }
    
            AuthenticationCredentials tokenCredentials =
                serviceManagement.Authenticate(
                    authCredentials);
    
               if (isOrgServiceRequest)
            {
                // Set SecurityTokenResponse for the current organization.
                currentConfig.OrganizationTokenResponse = tokenCredentials.SecurityTokenResponse;
                // Set classType to ManagedTokenOrganizationServiceProxy.
                classType = typeof(ManagedTokenOrganizationServiceProxy);
    
            }
            else
            {
                // Set classType to ManagedTokenDiscoveryServiceProxy.
                classType = typeof(ManagedTokenDiscoveryServiceProxy);
            }
    
            // Invokes ManagedTokenOrganizationServiceProxy or ManagedTokenDiscoveryServiceProxy 
            // (IServiceManagement<TService>, SecurityTokenResponse) constructor.
            return (TProxy)classType
            .GetConstructor(new Type[] 
                { 
                    typeof(IServiceManagement<TService>), 
                    typeof(SecurityTokenResponse) 
                })
            .Invoke(new object[] 
                { 
                    serviceManagement, 
                    tokenCredentials.SecurityTokenResponse 
                });
        }
    
        // Obtain discovery/organization service proxy for ActiveDirectory environment.
        if (isOrgServiceRequest)
        {
            classType = typeof(ManagedTokenOrganizationServiceProxy);
        }
        else
        {
            classType = typeof(ManagedTokenDiscoveryServiceProxy);
        }
    
        // Invokes ManagedTokenDiscoveryServiceProxy or ManagedTokenOrganizationServiceProxy 
        // (IServiceManagement<TService>, ClientCredentials) constructor.
        return (TProxy)classType
            .GetConstructor(new Type[] 
               { 
                   typeof(IServiceManagement<TService>), 
                   typeof(ClientCredentials)
               })
           .Invoke(new object[] 
               { 
                   serviceManagement, 
                   authCredentials.ClientCredentials  
               });
    }
    • Public Snippets
    • Channels Snippets