當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。