当前位置: 首页>>代码示例>>Java>>正文


Java HTTP类代码示例

本文整理汇总了Java中org.cybergarage.http.HTTP的典型用法代码示例。如果您正苦于以下问题:Java HTTP类的具体用法?Java HTTP怎么用?Java HTTP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HTTP类属于org.cybergarage.http包,在下文中一共展示了HTTP类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addEncodeing2Request

import org.cybergarage.http.HTTP; //导入依赖的package包/类
private void addEncodeing2Request(NetworkResponse response) {
    try {
        String type = response.headers.get(HTTP.CONTENT_TYPE);
        if (type == null) {
            //Content-Type:
            Log.d("RVA", "content type was null");
            type = TYPE_UTF8_CHARSET;
            response.headers.put(HTTP.CONTENT_TYPE, type);
        } else if (!type.contains("charset")) {
            //Content-Type: text/plain;
            Log.d("RVA", "charset was null, added encode utf-8");
            type += ";" + TYPE_UTF8_CHARSET;
            response.headers.put(HTTP.CONTENT_TYPE, type);
        } else {
            //Nice! Content-Type: text/plain; charset=utf-8'
            Log.d("RVA", "charset is " + type);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:freedomofme,项目名称:Netease,代码行数:23,代码来源:RequestSingletonFactory.java

示例2: isURL

import org.cybergarage.http.HTTP; //导入依赖的package包/类
private boolean isURL(String referenceUrl, String url)
{
	if (referenceUrl ==null || url == null)
		return false;
	boolean ret = url.equals(referenceUrl);
	if (ret == true)
		return true;
	String relativeRefUrl = HTTP.toRelativeURL(referenceUrl, false);
	ret = url.equals(relativeRefUrl);
	if (ret == true)
		return true;
	return false;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:14,代码来源:Service.java

示例3: parse

import org.cybergarage.http.HTTP; //导入依赖的package包/类
public Node parse(URL locationURL) throws ParserException
{
	String host = locationURL.getHost();
	int port = locationURL.getPort();
	String uri = locationURL.getPath();
	
	try {
 		HttpURLConnection urlCon = (HttpURLConnection)locationURL.openConnection();
		urlCon.setRequestMethod("GET");
		urlCon.setRequestProperty(HTTP.CONTENT_LENGTH,"0");
		if (host != null)
			urlCon.setRequestProperty(HTTP.HOST, host);

		InputStream urlIn = urlCon.getInputStream();

		Node rootElem = parse(urlIn);
		
		urlIn.close();
		urlCon.disconnect();

		return rootElem;
		
	} catch (Exception e) {
		//throw new ParserException(e);
	}

	HTTPRequest httpReq = new HTTPRequest();
	httpReq.setMethod(HTTP.GET);
	httpReq.setURI(uri);
	HTTPResponse httpRes = httpReq.post(host, port);
	if (httpRes.isSuccessful() == false)
		throw new ParserException("HTTP comunication failed: no answer from peer." +
				"Unable to retrive resoure -> "+locationURL.toString());
	String content = new String(httpRes.getContent());
	ByteArrayInputStream strBuf = new ByteArrayInputStream(content.getBytes());
	return parse(strBuf);
}
 
开发者ID:jimdowling,项目名称:nat-traverser,代码行数:38,代码来源:Parser.java

示例4: SSDPNotifyRequest

import org.cybergarage.http.HTTP; //导入依赖的package包/类
public SSDPNotifyRequest()
{
	setMethod(HTTP.NOTIFY);
	setURI("*");
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:6,代码来源:SSDPNotifyRequest.java

示例5: parse

import org.cybergarage.http.HTTP; //导入依赖的package包/类
public Node parse(URL locationURL) throws ParserException
{
	String host = locationURL.getHost();
	int port = locationURL.getPort();
	// Thanks for Hao Hu 
	if (port == -1)
		port = 80;
	String uri = locationURL.getPath();
	
	try {
 		HttpURLConnection urlCon = (HttpURLConnection)locationURL.openConnection();
		// I2P mods to prevent hangs (see HTTPRequest for more info)
		// this seems to work, getInputStream actually does the connect(),
		// (as shown by a thread dump)
		// so we can set these after openConnection()
		// Alternative would be foo = new HttpURLConnection(locationURL); foo.set timeouts; foo.connect()
		urlCon.setConnectTimeout(2*1000);
		urlCon.setReadTimeout(1000);
		urlCon.setRequestMethod("GET");
		urlCon.setRequestProperty(HTTP.CONTENT_LENGTH,"0");
		if (host != null)
			urlCon.setRequestProperty(HTTP.HOST, host);

		InputStream urlIn = urlCon.getInputStream();

		Node rootElem = parse(urlIn);
		
		urlIn.close();
		urlCon.disconnect();

		return rootElem;
		
	} catch (Exception e) {
		//throw new ParserException(e);
	}

	HTTPRequest httpReq = new HTTPRequest();
	httpReq.setMethod(HTTP.GET);
	httpReq.setURI(uri);
	HTTPResponse httpRes = httpReq.post(host, port);
	if (httpRes.isSuccessful() == false)
		throw new ParserException("HTTP comunication failed: no answer from peer." +
				"Unable to retrive resoure -> "+locationURL.toString());
	String content = new String(httpRes.getContent());
	ByteArrayInputStream strBuf = new ByteArrayInputStream(content.getBytes());
	return parse(strBuf);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:48,代码来源:Parser.java

示例6: SOAPRequest

import org.cybergarage.http.HTTP; //导入依赖的package包/类
public SOAPRequest()
{
	setContentType(SOAP.CONTENT_TYPE);
	setMethod(HTTP.POST);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:6,代码来源:SOAPRequest.java


注:本文中的org.cybergarage.http.HTTP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。