首先,我们先看一下http的头信息到底是什么:
HTTP(HyperTextTransferProtocol) 即超文本传输协议,目前网页传输的的通用协议。HTTP协议采用了请求/响应模型,浏览器或其他客户端发出请求,服务器给与响应。就整个网络资源传输而 言,包括message-header和message-body两部分。首先传递message- header,即http header消息。http header 消息通常被分为4个部分: general header, request header, response header, entity header。但是这种分法就理解而言,感觉界限不太明确,根据日常使用,大体分为Request和Response两部分。
在通常的servlet/jsp应用中,我们只是从http的header中取得信息,如果要设置信息,需要用到HttpClient,具体的设置方法如下:
HttpResponse response = null;
HttpGet get = new HttpGet(url);
getaddHeader("Accept", "text/html");
getaddHeader("Accept-Charset", "utf-8");
getaddHeader("Accept-Encoding", "gzip");
getaddHeader("Accept-Language", "en-US,en");
getaddHeader("User-Agent", "Mozilla/50 (X11; Linux x86_64) AppleWebKit/53722 (KHTML, like Gecko) Chrome/2501364160 Safari/53722");
response = clientexecute(get);
HttpEntity entity = responsegetEntity();
Header header = entitygetContentEncoding();
if (header != null)
{
HeaderElement[] codecs = headergetElements();
for (int i = 0; i < codecslength; i++)
{
if (codecs[i]getName()equalsIgnoreCase("gzip"))
{
responsesetEntity(new GzipDecompressingEntity(entity));
}
}
}
return response;
其中,client为一个HttpClient的实力,创建方式如:
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistryregister(new Scheme("http", 80, PlainSocketFactorygetSocketFactory()));
schemeRegistryregister(new Scheme("https", 443, SSLSocketFactorygetSocketFactory()));
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
cmsetMaxTotal(200);
cmsetDefaultMaxPerRoute(2);
HttpHost googleResearch = new HttpHost("researchgooglecom", 80);
HttpHost wikipediaEn = new HttpHost("enwikipediaorg", 80);
cmsetMaxPerRoute(new HttpRoute(googleResearch), 30);
cmsetMaxPerRoute(new HttpRoute(wikipediaEn), 50);
DefaultHttpClient client = new DefaultHttpClient(cm);
以上就是关于如何获取http请求头中的uuid全部的内容,包括:如何获取http请求头中的uuid、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)