本文整理汇总了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();
}
}
示例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;
}
示例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);
}
示例4: SSDPNotifyRequest
import org.cybergarage.http.HTTP; //导入依赖的package包/类
public SSDPNotifyRequest()
{
setMethod(HTTP.NOTIFY);
setURI("*");
}
示例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);
}
示例6: SOAPRequest
import org.cybergarage.http.HTTP; //导入依赖的package包/类
public SOAPRequest()
{
setContentType(SOAP.CONTENT_TYPE);
setMethod(HTTP.POST);
}