HTTPCLIENT is connected by proxy connection server

zhaozj2021-02-11  227

The general method of using a proxy is to implement the static method of HTTPConnection. SetProxyServer implementation:

HttpConnection.SetProxyServer ("My.Proxy.dom", 8008);

The HTTPConnection object generated after calling this method will establish a server connection through the agent.

Specific aid use agent:

SetCurrentProxy ()

You can also set up some servers don't use proxy:

HttpConnection.dontProxyFor ("localhost");

If the proxy server requires username password authentication:

AuthorizationInfo.adddigestauthorization (Host, Proxyport, ", Name, Pass);

The third parameter is the authentication domain. The general proxy server can be set to an empty string unless you know the exact domain of the server.

There is another way to use defaultauthhandler:

DefaultAuthhandler.SetAuthorizationPRMPTER (New MyAuThPRompter (PA_NAME, PA_Pass);

MyAuthPRompter is a custom class that implements the AuthorizationPRMPTER interface:

Class MyAuthPrompter Implements AuthorizationPRompter

{

PRIVATE STRING PA_NAME, PA_PASS;

Private boolean been_here = false;

MyAuthPRompter (String Pa_name, String Pa_pass) {

THIS.PA_NAME = PA_NAME;

THIS.PA_PASS = PA_PASS;

}

Public NVPAIR GetUserNamePassword (AuthorizationInfo Challenge, Boolean Forproxy) {

IF (Forproxy && Pa_name! = null) {

IF (been_here) {

System.out.println ("Proxy Authorization Failed";

Return NULL;

}

BEEN_HERE = TRUE;

Return New NVPAIR (PA_NAME, PA_PASS);

}

IF (been_here) {

System.out.println ("Proxy Authorization Succeeded";

}

// Print Out All Challenge Info

IF (Forproxy)

System.out.Println ("The Proxy Requires Authorization);

Else

System.out.Println ("The Server Requires Authorization for this Resource");

Return NULL;

}

}

About page certification

Does a page require authentication, as well as information requiring authentication, can be obtained by httpclient / doc / getAuthinfo.java:

Java getAuthinfo http://some.host.dom/the/file.html

The program will output authentication information including the authentication domain.

Note:

Download the page that requires the user to authenticate,

HttpClient

The username password and the scope input box will pop up. If you need to cancel the input pop-up dialog, you can call

HttpConnection

of

SETALLOWUSERINTERACTION (FALSE) method.

转载请注明原文地址:https://www.9cbs.com/read-5789.html

New Post(0)