`
zzzzzz5530041
  • 浏览: 34316 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

HTTPConnector 发送请求

 
阅读更多
package com.****util;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.net.ssl.KeyManagerFactory;

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

 
 

public class HttpConnector {

	static Log logger = LogFactory.getLog(HttpConnector.class);

	 public HttpConnector(){
		 this.init();
	 }
	private String URLs[];
	private String proxyHost = null;
	private String proxyPort = "8080";
	private String retryCount = "1";
	private String sslPort = "443";
	private String algorithm = KeyManagerFactory.getDefaultAlgorithm();
	private String storeKey;
	private String trustKey;
	private String protocolType ;
	private String keyStoreName;
	private String trustStoreName;
	private String[] subUrls;

	 
	/**
	 * init parameters 
	 */
	public void init(){
		logger.debug("enter httpconnector init()");
		this.URLs=new String[]{Utils.getProperty("jpc.httpconnector.urls")};
		logger.debug("URLs ===>"+URLs[0]);
		this.proxyPort=Utils.getProperty("jpc.httpconnector.proxyport");   
		logger.debug("proxyPort ===>"+proxyPort);
		this.retryCount=Utils.getProperty("jpc.httpconnector.retrycount") ;  
		if(StringUtils.isEmpty(this.retryCount)){
			this.retryCount="1";
		}
		logger.debug("retryCount ===>"+retryCount);
		this.algorithm=KeyManagerFactory.getDefaultAlgorithm();
		this.storeKey=Utils.getProperty("jpc.httpconnector.storekey") ; 
		logger.debug("storeKey ===>"+storeKey);
		this.trustStoreName=Utils.getProperty("jpc.httpconnector.truststorename"); 
		logger.debug("trustStoreName ===>"+trustStoreName);
		this.keyStoreName=Utils.getProperty("jpc.httpconnector.keystorename"); 
		logger.debug("keyStoreName ===>"+keyStoreName);
		this.subUrls=new String[]{Utils.getProperty("jpc.httpconnector.suburls")}; 
		logger.debug("subUrls ===>"+subUrls[0]);
		this.protocolType=Utils.getProperty("jpc.httpconnector.protocoltype"); 
		logger.debug("protocolType ===>"+protocolType);
		this.sslPort=Utils.getProperty("jpc.httpconnector.sslport" ); 
		logger.debug("sslPort ===>"+sslPort);
		if(StringUtils.isEmpty(this.sslPort)){
			this.retryCount="443";
		}
		this.trustKey=Utils.getProperty("jpc.httpconnector.trustkey"); 
		logger.debug("trustKey ===>"+trustKey);
	}
	 

	public String sendEntity(RequestEntity requestEntiry)throws MessagingException {
		final String debugHeader = getClass().getName() + ".sendEntity(): ";
		HttpClient client = new HttpClient();
		InputStream stream;
		String responseStr = "";
		this.proxyHost = this.proxyHost == null|| this.proxyHost.trim().equals("") ? null : this.proxyHost
				.trim();
		if (this.proxyHost != null) {
			client.getHostConfiguration().setHost(this.proxyHost,
					Integer.parseInt(this.proxyPort));
		}

		if ("https".equals(protocolType)) {
			Protocol https = new Protocol(protocolType,
					new JPCSSLProtocolSocketFactory(keyStoreName, storeKey
							.toCharArray(), algorithm, trustStoreName, trustKey
							.toCharArray(), algorithm, null),Integer.parseInt(sslPort));
			logger.debug("https  "+https);
			Protocol.registerProtocol(protocolType, https);
			
		}
		PostMethod method = new PostMethod(this.URLs[0] + subUrls[0]);
		
		client.getParams().setAuthenticationPreemptive(true);
		logger.debug("client====>"+client);
		method.setRequestEntity(requestEntiry);
		method.setDoAuthentication(true);
		method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
				new DefaultHttpMethodRetryHandler(Integer.parseInt(retryCount), false));
		logger.debug("method  "+method);
		try {
			client.executeMethod(method);
			String statusCode = String.valueOf(method.getStatusCode());
			if (statusCode.startsWith("4") || statusCode.startsWith("5")) {
				logger.error(debugHeader
								+ "For the URL: "
								+ this.URLs[0]
								+ ", the status code is other than 200. Actual Status Code is : "
								+ statusCode
								+ " and Hence trying with other urls. ");
			} else {
				stream = method.getResponseBodyAsStream();
				logger.debug("stream  "+stream);
				responseStr = convertStream(stream);
			}
		} catch (Exception e) {
			logger.error("Exception occurs:" + e.getMessage());
			throw new ConnectorException(debugHeader
					+ "Exception Occured with  the url(s) = " + this.URLs[0]
					+ subUrls[0] + ", and returning null");
		} finally {
			if (method != null) {
				method.releaseConnection();
			}
		}
		return responseStr;
	}
	/**
	 * convert inputstream to String
	 * @param stream comes from host
	 * @return
	 * @throws IOException
	 */
	private String convertStream(InputStream stream) throws IOException {

		BufferedInputStream bis = new BufferedInputStream(stream);
		int c = -1;
		StringBuffer sbf = new StringBuffer("");
		if ((c = bis.read()) != -1) {
			do {
				sbf.append(String.valueOf((char) c));
			} while ((c = bis.read()) != -1);
		}
		return sbf.toString();
	}
}

package com.***.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;

import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;

import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class JPCSSLProtocolSocketFactory implements SecureProtocolSocketFactory {
	private static final Log logger = LogFactory.getLog(JPCSSLProtocolSocketFactory.class);
    private SSLContext sslContext;
    private SSLSocketFactory sslSocketFactory;
	public JPCSSLProtocolSocketFactory(String keyStorePath, char[] keystoreStorepass,
			String keyManagerFactoryAlgorithm, String trustStorePath, char[] truststoreStorepass,
			String trustManagerFactoryAlgorithm, String keystoreType) {
		try {
			logger.debug("enter JPCSSLProtocolSocketFactory constructor...");
			StringBuffer sb = new StringBuffer();
			logger.debug(sb.append("keyStorePath="+keyStorePath+",keystoreStorepass="+new String(keystoreStorepass)+",keyManagerFactoryAlgorithm="+keyManagerFactoryAlgorithm
					+",trustStorePath="+trustStorePath+",truststoreStorepass="+new String(truststoreStorepass)+",trustManagerFactoryAlgorithm="+trustManagerFactoryAlgorithm+",keystoreType="+keystoreType));

			if (trustStorePath == null || truststoreStorepass == null || trustManagerFactoryAlgorithm == null) {
			    throw new IllegalArgumentException("trustStorePath == null || truststoreStorepass == null || trustManagerFactoryAlgorithm == null");
			}
			
			KeyManager[] kms = null;
			TrustManager[] tms = null;
			KeyStore keystore = null;
			if (keyStorePath != null && keyStorePath.trim().length() > 0) {

			    if (keystoreStorepass == null || keyManagerFactoryAlgorithm == null) {
			        throw new IllegalArgumentException("keystoreStorepass == null || keyManagerFactoryAlgorithm == null");
			    }

			    if (keystoreType == null || keystoreType.trim().length() == 0) {
			        keystore = loadKeyStore(keyStorePath, keystoreStorepass);
			    } else {
			         
						keystore = loadKeyStore(keystoreType, keyStorePath, keystoreStorepass);
			    }
			    KeyManagerFactory kmFactory =KeyManagerFactory.getInstance(keyManagerFactoryAlgorithm);
			    logger.debug("kmFactory === "+kmFactory);
				kmFactory.init(keystore, keystoreStorepass);
			    kms = kmFactory.getKeyManagers();
			    logger.debug("kms === "+kms);
			    if (new String(truststoreStorepass).trim().length() == 0) {
			        logger.debug("truststoreStorepass:(" + truststoreStorepass.toString() + ") set to null");
			        truststoreStorepass = null;
			      }
			      KeyStore truststore = loadKeyStore(trustStorePath, truststoreStorepass);
			      logger.debug("truststore === "+truststore);
			      TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(trustManagerFactoryAlgorithm);
			      logger.debug("tmFactory === "+tmFactory);
			      tmFactory.init(truststore);
			      logger.debug("tmFactory === "+tmFactory);
			      
			      tms = tmFactory.getTrustManagers();
			      logger.debug("tms === "+tms);
			      this.sslContext = SSLContext.getInstance("SSL");
			      logger.debug("sslContext === "+sslContext);
			      this.sslContext.init(kms, tms, null);
			      this.sslSocketFactory = this.sslContext.getSocketFactory();
			      logger.debug("sslSocketFactory === "+sslSocketFactory);
			}
		} catch (KeyManagementException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (KeyStoreException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnrecoverableKeyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Socket createSocket(final String host, final int port, final InetAddress clientHost, int clientPort) throws IOException {
        return sslSocketFactory.createSocket(host, port, clientHost, clientPort);
    }

    /**
     * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int)
     */
    public Socket createSocket(final String host, final int port) throws IOException {
        return sslSocketFactory.createSocket(host, port);
    }

    /**
     * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
     */
    public Socket createSocket(final Socket socket, final String host, final int port, final boolean autoClose) throws IOException {
        return sslSocketFactory.createSocket(socket, host, port, autoClose);
    }
/*
 * 	//invoked after invoke httpClient.executeMethod() method
 * @see org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket(java.lang.String, int, java.net.InetAddress, int, org.apache.commons.httpclient.params.HttpConnectionParams)
 */
    public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3, HttpConnectionParams arg4) throws IOException, UnknownHostException, ConnectTimeoutException {
    
    	return sslSocketFactory.createSocket(arg0, arg1,arg2,arg3);
    }
	public static KeyStore loadKeyStore(String keyStoreFilePath, char keyStorePassword[]) {
        try {
            return loadKeyStore(KeyStore.getDefaultType(), keyStoreFilePath, keyStorePassword);
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
            	logger.debug("error when load the key store,will return null");
            }
        }

        return null;
    }
	public static KeyStore loadKeyStore(String keyStoreType, String keyStoreResource, char keyStorePassword[]) throws Exception {
        InputStream in = null;
        try {
            KeyStore keystore;
            try {
                KeyStore keyStore = KeyStore.getInstance(keyStoreType);
                logger.debug("keystore=="+keyStore);
                in = JPCSSLProtocolSocketFactory.class.getResourceAsStream(keyStoreResource);
                logger.debug("in=="+in);
                if (in == null)
                    throw new Exception("file [" + keyStoreResource + "] does not exist");
                keyStore.load(in, keyStorePassword);
                logger.debug("keyStore=="+keyStore);
                keystore = keyStore;
                logger.debug("keystore  "+keystore);
            } catch (IOException ioe) {
                throw new Exception(ioe.getMessage(), ioe);
            } catch (Exception e) {
                throw new Exception(e.getMessage(), e);
            }
            return keystore;
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (IOException ioe1) {
                }
        }
    }

}
 
/**调用*/
public static String generateSMAL(String customerID,String samlentryPoint) throws Exception{
	  	logger.debug("enter generateSMAL ()");
		StringBuffer credentialData =new StringBuffer();
		credentialData.append("<CUSTOMERID>").append(customerID).append("</CUSTOMERID>")
		.append("<ENTRYPOINTID>").append(samlentryPoint).append("</ENTRYPOINTID>");
		String issueraddress =Utils.getProperty("jpcegainsamlissueraddress");
		logger.debug("issueraddress===>"+issueraddress);
		
		logger.debug("credentialData ==="+credentialData);
		VelocityContext velocityContext = new VelocityContext();
	    velocityContext.put("credentialData",credentialData);
	    velocityContext.put("issueraddress",issueraddress);
		VelocityEngine velocity = new VelocityEngine();
		String soapTokenRequestFilePath=Utils.getProperty("jpcegainsoaptokenrequestfilepath");
		logger.debug("soapTokenRequestFilePath ===>"+soapTokenRequestFilePath);
		velocity.setProperty("file.resource.loader.path", soapTokenRequestFilePath); 
		 StringWriter messageBody =null;
		velocity.init();
		Template template = velocity.getTemplate("SoapTokenRequest.vm", "UTF-8");
		messageBody = new StringWriter();
		template.merge(velocityContext, messageBody);
		logger.debug("SoapTokenRequest request body==="+messageBody.toString());
		HttpConnector hc=new HttpConnector();
		logger.debug("HttpConnector ===="+hc);
		StringRequestEntity requestEntity = new StringRequestEntity(messageBody.toString(), "text/xml", "UTF-8");
		logger.debug("requestEntity =="+requestEntity);
	    String responseMessage = hc.sendEntity(requestEntity);
	    logger.debug("responseMessage ==== "+responseMessage);
	    String token=parseResponse(responseMessage);
	    logger.debug("SAML token==="+token);
	    return token;
	}
  private static String parseResponse(String responseMessage) throws Exception {
	// TODO Auto-generated method stub
	logger.debug("responseMessage====>"+responseMessage);
	String token="";
	try {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		Document doc = db.parse(new ByteArrayInputStream(responseMessage.getBytes()));
		NodeList nl = doc.getElementsByTagName("csts:SAMLResponse");
		Node my_node = nl.item(0);
		logger.debug("my_node====>"+my_node);
		token = my_node.getFirstChild().getNodeValue();
	} catch (Exception e) {
		
		logger.error("facing error when parse response=="+e.getMessage());
		e.printStackTrace();
		throw new Exception("facing error when parse response=="+e.getMessage());
	}
	return token;
}
 import javax.net.ssl.KeyManagerFactory; import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.citi.ito.jpc.common.Utils; import com.*******.messaging.exception.ConnectorException; import com.*******.exception.MessagingException; public class HttpConnector { static Log logger = LogFactory.getLog(HttpConnector.class); public HttpConnector(){ this.init(); } private String URLs[]; private String proxyHost = null; private String proxyPort = "8080"; private String retryCount = "1"; private String sslPort = "443"; private String algorithm = KeyManagerFactory.getDefaultAlgorithm(); private String storeKey; private String trustKey; private String protocolType ; private String keyStoreName; private String trustStoreName; private String[] subUrls; /** * init parameters */ public void init(){ logger.debug("enter httpconnector init()"); this.URLs=new String[]{Utils.getProperty("jpc.httpconnector.urls")}; logger.debug("URLs ===>"+URLs[0]); this.proxyPort=Utils.getProperty("jpc.httpconnector.proxyport"); logger.debug("proxyPort ===>"+proxyPort); this.retryCount=Utils.getProperty("jpc.httpconnector.retrycount") ; if(StringUtils.isEmpty(this.retryCount)){ this.retryCount="1"; } logger.debug("retryCount ===>"+retryCount); this.algorithm=KeyManagerFactory.getDefaultAlgorithm(); this.storeKey=Utils.getProperty("jpc.httpconnector.storekey") ; logger.debug("storeKey ===>"+storeKey); this.trustStoreName=Utils.getProperty("jpc.httpconnector.truststorename"); logger.debug("trustStoreName ===>"+trustStoreName); this.keyStoreName=Utils.getProperty("jpc.httpconnector.keystorename"); logger.debug("keyStoreName ===>"+keyStoreName); this.subUrls=new String[]{Utils.getProperty("jpc.httpconnector.suburls")}; logger.debug("subUrls ===>"+subUrls[0]); this.protocolType=Utils.getProperty("jpc.httpconnector.protocoltype"); logger.debug("protocolType ===>"+protocolType); this.sslPort=Utils.getProperty("jpc.httpconnector.sslport" ); logger.debug("sslPort ===>"+sslPort); if(StringUtils.isEmpty(this.sslPort)){ this.retryCount="443"; } this.trustKey=Utils.getProperty("jpc.httpconnector.trustkey"); logger.debug("trustKey ===>"+trustKey); } public String sendEntity(RequestEntity requestEntiry)throws MessagingException { final String debugHeader = getClass().getName() + ".sendEntity(): "; HttpClient client = new HttpClient(); InputStream stream; String responseStr = ""; this.proxyHost = this.proxyHost == null|| this.proxyHost.trim().equals("") ? null : this.proxyHost .trim(); if (this.proxyHost != null) { client.getHostConfiguration().setHost(this.proxyHost, Integer.parseInt(this.proxyPort)); } if ("https".equals(protocolType)) { Protocol https = new Protocol(protocolType, new JPCSSLProtocolSocketFactory(keyStoreName, storeKey .toCharArray(), algorithm, trustStoreName, trustKey .toCharArray(), algorithm, null),Integer.parseInt(sslPort)); logger.debug("https "+https); Protocol.registerProtocol(protocolType, https); } PostMethod method = new PostMethod(this.URLs[0] + subUrls[0]); client.getParams().setAuthenticationPreemptive(true); logger.debug("client====>"+client); method.setRequestEntity(requestEntiry); method.setDoAuthentication(true); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(Integer.parseInt(retryCount), false)); logger.debug("method "+method); try { client.executeMethod(method); String statusCode = String.valueOf(method.getStatusCode()); if (statusCode.startsWith("4") || statusCode.startsWith("5")) { logger.error(debugHeader + "For the URL: " + this.URLs[0] + ", the status code is other than 200. Actual Status Code is : " + statusCode + " and Hence trying with other urls. "); } else { stream = method.getResponseBodyAsStream(); logger.debug("stream "+stream); responseStr = convertStream(stream); } } catch (Exception e) { logger.error("Exception occurs:" + e.getMessage()); throw new ConnectorException(debugHeader + "Exception Occured with the url(s) = " + this.URLs[0] + subUrls[0] + ", and returning null"); } finally { if (method != null) { method.releaseConnection(); } } return responseStr; } /** * convert inputstream to String * @param stream comes from host * @return * @throws IOException */ private String convertStream(InputStream stream) throws IOException { BufferedInputStream bis = new BufferedInputStream(stream); int c = -1; StringBuffer sbf = new StringBuffer(""); if ((c = bis.read()) != -1) { do { sbf.append(String.valueOf((char) c)); } while ((c = bis.read()) != -1); } return sbf.toString(); } }

 ##################SAML#######################
jpcegainsamlentrypoint=1000
jpcegainsamlissueraddress=*****
jpcegainsoaptokenrequestfilepath=/*****

#################JPC HTTP CONNECTOR######################

jpc.httpconnector.urls=*****
jpc.httpconnector.proxyport=8080
jpc.httpconnector.retrycount=1
jpc.httpconnector.storekey=*****
jpc.httpconnector.truststorename=/resources/SSO/EGAIN/saixu33_truststore.jks
jpc.httpconnector.keystorename=/resources/SSO/EGAIN/saixu33_keystore.jks
jpc.httpconnector.suburls=/*****
jpc.httpconnector.protocoltype=https
jpc.httpconnector.sslport=443
jpc.httpconnector.trustkey=citi1234

分享到:
评论

相关推荐

    Java发https请求证书问题

    3. **设置请求方法**:接下来通过 `setRequestMethod()` 方法设置 HTTP 请求类型为 POST。 4. **启用输入输出流**:分别调用 `setDoOutput(true)` 和 `setDoInput(true)` 方法开启数据的输出和输入功能。 5. **打印...

    Android客户端发送请求中文乱码问题完美解决

    Android客户端发送请求中文乱码问题是指在Android客户端向服务器端提交请求时出现的中文乱码问题,这是由于在HTTP请求中,中文字符被编码为乱码字符所致。为了解决这个问题,我们可以从两个方面入手:客户端编码和...

    tomcat发送https请求配置

    Tomcat 发送 HTTPS 请求配置 Tomcat 是一个流行的 Web 服务器软件,用于部署基于 Java 的 Web 应用程序。为了确保数据传输的安全性,需要使用 HTTPS 协议来加密数据。在本文中,我们将介绍如何配置 Tomcat 来发送 ...

    j2me Http Get和Post请求总结

    在J2ME中,我们可以使用`javax.microedition.io.Connector`类和`HttpConnection`接口来实现GET请求。创建一个`HttpConnection`对象,设置其URL,然后打开连接,最后通过`InputStream`读取响应数据。需要注意的是,...

    Laravel开发-api-connector

    2. **方法封装**:为每个API端点创建对应的方法,每个方法内部调用`Http` Facade发送请求。 3. **错误处理**:处理API响应中的错误,例如超时、无响应或返回错误状态码。 4. **数据转换**:将API返回的原始数据转换...

    Mule通过HTTP连接并传参给webService例子

    6. **测试和调试**:使用Anypoint Studio的调试工具或部署到Mule运行时进行测试,确保能够正确发送请求并接收期望的响应。 此外,为了提高代码的可维护性和重用性,可以考虑封装HTTP调用为一个自定义组件或使用Mule...

    http、mysqlconnector和gson.jar.rar

    在Android应用中,我们通常使用HTTP库来发送网络请求,获取或提交数据。压缩包中的“http”可能是指一个轻量级的HTTP客户端库,如Apache HttpClient或者OkHttp。这些库允许开发者方便地发起GET、POST等HTTP请求,...

    ajax异步请求小结

    2. **发送请求** - **GET请求**: ```javascript xhr.open('get', 'check_uname.do?username=tom', true); xhr.onreadystatechange = handler; xhr.send(null); ``` - **POST请求**: ```javascript xhr....

    lua-resty-post:用于openresty的HTTP发布实用程序

    这个库主要为OpenResty环境提供了一个简洁的API,用于构造和发送HTTP POST请求。它支持多种HTTP方法,包括POST、PUT、DELETE等,这使得在处理RESTful API时更加灵活。通过使用Lua语言的内联语法,我们可以直接在...

    JSP中 ajax的get请求的中文乱码问题的解决方法.pdf

    &lt;Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /&gt; ``` 这样,服务器在解析GET请求参数时会使用正确的字符编码,避免乱码问题。 3. **...

    http.rar_HTTP 网页

    MIDlet通过HTTP进行网络连接,意味着它们可以利用HTTP协议来获取网络资源,如网页数据,实现功能如浏览网页、发送请求、接收响应等。 以下是一些关于MIDlet使用HTTP访问网页的关键知识点: 1. **JSR 82 API**:...

    S19-再看tomcat架构与请求处理流程1

    Endpoint 监听特定端口(如 `8080`),接收客户端通过 TCP/IP 协议发送的 HTTP 请求。它会创建线程来处理每个新的连接,并将接收到的数据传递给下一个处理阶段。 2. **Processor 组件**:Processor 在应用层处理 ...

    HTTP 的工作原理

    请求阶段,客户端向服务器发送HTTP请求,请求可以是GET或POST两种主要方式,GET用于获取资源,POST用于提交数据;应答阶段,服务器处理请求并返回响应;最后,连接结束,客户端与服务器断开连接,以便其他设备能够...

    Python-Python程序用于嗅探未加密的探测请求并将其记录到MySQL

    未加密的探测请求可能包括HTTP GET或POST请求,这些请求在传输时如果没有使用HTTPS,其内容是明文的,容易被嗅探。对于网络安全来说,保护这些信息不被窃取至关重要。因此,使用Python来嗅探并记录这些请求,可以...

    TOMCAT原理详解及请求过程

    - **定义**:`Connector`组件负责接收客户端的HTTP请求并将这些请求传递给相关的`Container`进行处理。 - **属性**: - **protocol**:定义通信协议,默认为HTTP/1.1。 - **port**:监听端口号,默认为8080。 -...

    11 Web服务开发(更新版)1

    - **底层接口**:如果需要更多控制,开发者可以直接创建HttpConnector对象处理HTTP连接,使用SoapSerializer生成SOAP消息,通过HttpConnector发送,并使用SoapReader解析返回的SOAP响应。 5. **Android中的Web服务...

    How_Tomcat_Works中文版

    2. **解析请求**:Connector解析客户端发送的HTTP请求,提取请求头、URL等信息。 3. **分发请求**:Connector根据解析出的URL将请求分发给对应的Container进行处理。 4. **处理请求**:Container接收到请求后,...

    Tomcat---Connector 分析.docx

    总的来说,`Connector`是Tomcat中连接客户端和Servlet容器的桥梁,它实现了网络通信的基本功能,包括TCP/IP连接的建立、HTTP协议的解析以及请求的转发和响应的发送。通过灵活配置`Connector`,可以适应不同的网络...

Global site tag (gtag.js) - Google Analytics