本文整理汇总了Java中javax.microedition.io.HttpConnection类的典型用法代码示例。如果您正苦于以下问题:Java HttpConnection类的具体用法?Java HttpConnection怎么用?Java HttpConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpConnection类属于javax.microedition.io包,在下文中一共展示了HttpConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInvokeContext
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
protected Object getInvokeContext() throws IOException {
HttpConnection conn = (HttpConnection)Connector.open(uri, Connector.READ_WRITE);
if (keepAlive) {
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Keep-Alive", Integer.toString(keepAliveTimeout));
}
else {
conn.setRequestProperty("Connection", "Close");
}
conn.setRequestProperty("Cookie", cookieManager.getCookie(conn.getHost(),
conn.getFile(),
conn.getProtocol().equals("https")));
for (Enumeration e = headers.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
conn.setRequestProperty(key, (String) headers.get(key));
}
return conn;
}
示例2: getInputStream
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
protected InputStream getInputStream(Object context) throws IOException {
HttpConnection conn = (HttpConnection) context;
int i = 1;
String key = null;
Vector cookieList = new Vector();
while((key=conn.getHeaderFieldKey(i)) != null) {
if (key.toLowerCase().equals("set-cookie") ||
key.toLowerCase().equals("set-cookie2")) {
cookieList.addElement(conn.getHeaderField(i));
}
i++;
}
cookieManager.setCookie(cookieList, conn.getHost());
InputStream istream = conn.openInputStream();
return istream;
}
示例3: getInvokeContext
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
protected Object getInvokeContext() throws IOException {
HttpConnection conn = (HttpConnection)Connector.open(uri, Connector.READ_WRITE);
if (keepAlive) {
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Keep-Alive", Integer.toString(keepAliveTimeout));
}
else {
conn.setRequestProperty("Connection", "Close");
}
conn.setRequestProperty("Cookie", cookieManager.getCookie(conn.getHost(),
conn.getFile(),
conn.getProtocol().equals("https")));
for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
Entry entry = (Entry) iter.next();
conn.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
}
return conn;
}
示例4: getInputStream
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
protected InputStream getInputStream(Object context) throws IOException {
HttpConnection conn = (HttpConnection) context;
int i = 1;
String key = null;
ArrayList cookieList = new ArrayList();
while((key=conn.getHeaderFieldKey(i)) != null) {
if (key.equalsIgnoreCase("set-cookie") ||
key.equalsIgnoreCase("set-cookie2")) {
cookieList.add(conn.getHeaderField(i));
}
i++;
}
cookieManager.setCookie(cookieList, conn.getHost());
InputStream istream = conn.openInputStream();
return istream;
}
示例5: getHeaderFieldNames
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
/**
* @inheritDoc
*/
public String[] getHeaderFieldNames(Object connection) throws IOException {
HttpConnection c = (HttpConnection)connection;
Vector r = new Vector();
int i = 0;
String key = c.getHeaderFieldKey(i);
while (key != null) {
if(r.indexOf(key) < 0) {
r.addElement(key);
}
i++;
key = c.getHeaderFieldKey(i);
}
if(r.size() == 0) {
return null;
}
String[] response = new String[r.size()];
for(int iter = 0 ; iter < response.length ; iter++) {
response[iter] = (String)r.elementAt(iter);
}
return response;
}
示例6: getHeaderFields
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
/**
* @inheritDoc
*/
public String[] getHeaderFields(String name, Object connection) throws IOException {
HttpConnection c = (HttpConnection) connection;
Vector r = new Vector();
int i = 0;
while (c.getHeaderFieldKey(i) != null) {
if (c.getHeaderFieldKey(i).equalsIgnoreCase(name)) {
String val = c.getHeaderField(i);
r.addElement(val);
}
i++;
}
if (r.size() == 0) {
return null;
}
String[] response = new String[r.size()];
for (int iter = 0; iter < response.length; iter++) {
response[iter] = (String) r.elementAt(iter);
}
return response;
}
示例7: getChallenge
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
public static String getChallenge(HttpConnection connection ) throws IOException {
final String AUTH_HEADER_HACK = "X-S60-Auth";
//technically the standard
String challenge = null;
if (challenge == null) {
challenge = connection.getHeaderField(AUTH_HEADER_HACK);
}
if (challenge == null) {
challenge = connection.getHeaderField(AUTH_HEADER_HACK.toLowerCase());
}
if (challenge == null) {
challenge = connection.getHeaderField("WWW-Authenticate");
}
if(challenge == null) {
challenge = connection.getHeaderField("www-authenticate");
}
return challenge;
}
示例8: HttpResponsePropertyFactory
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
public static HttpRequestProperties HttpResponsePropertyFactory(HttpConnection conn) throws IOException {
HttpRequestProperties ret = new HttpRequestProperties();
String[] expectedHeaders = new String [] { "Content-Language", "X-OpenRosa-Version"};
ret.date = conn.getHeaderFieldDate("Date", 0);
if(ret.date == 0) {
ret.date = conn.getHeaderFieldDate("date", 0);
}
for(String header : expectedHeaders) {
ret.setRequestProperty(header, getHeaderHelper(conn, header));
}
return ret;
}
示例9: urlToStream
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
/**
* Reads the content from the specified HTTP URL and returns InputStream
* where the contents are read.
*
* @return InputStream
* @throws IOException
*/
private InputStream urlToStream(String url) throws IOException {
// Open connection to the http url...
HttpConnection connection = (HttpConnection) Connector.open(url);
DataInputStream dataIn = connection.openDataInputStream();
byte[] buffer = new byte[1000];
int read = -1;
// Read the content from url.
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
while ((read = dataIn.read(buffer)) >= 0) {
byteout.write(buffer, 0, read);
}
dataIn.close();
// Fill InputStream to return with content read from the URL.
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteout.toByteArray());
return byteIn;
}
示例10: urlToStream
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
/**
* Reads the content from the specified HTTP URL and returns InputStream
* where the contents are read.
*
* @return InputStream
* @throws IOException
*/
private InputStream urlToStream(String url) throws IOException {
// Open connection to the http url...
HttpConnection connection = (HttpConnection) Connector.open(url);
DataInputStream dataIn = connection.openDataInputStream();
byte[] buffer = new byte[1000];
int read = -1;
// Read the content from url.
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
while ((read = dataIn.read(buffer)) >= 0) {
byteout.write(buffer, 0, read);
}
dataIn.close();
connection.close();
// Fill InputStream to return with content read from the URL.
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteout.toByteArray());
return byteIn;
}
示例11: submitBug
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
public static void submitBug(Location location, String text, String user) {
String url = API_URL + "addPOIexec?lat=" + location.getY() + "&lon=" + location.getX()
+ "&text=" + urlEncode(text) + "&format=js";
try {
HttpConnection httpConn = (HttpConnection) Connector.open(url);
ByteArrayOutputStream reply = new ByteArrayOutputStream();
InputStream in = httpConn.openDataInputStream();
for (int b = in.read(); b != -1; b = in.read()) {
reply.write(b);
}
in.close();
System.out.println("OpenStreetBugs reply: " + reply.toString());
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例12: getResponseAsSting
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
private static String getResponseAsSting(HttpConnection conn) throws IOException {
String result = "";
InputStream inputStream = null;
try {
inputStream = conn.openInputStream();
int len;
byte[] data = new byte[512];
do {
len = inputStream.read(data);
if(len > 0){
result += new String(data, 0, len);
}
} while(len > 0);
} catch (Exception e) {
if (e instanceof IOException) {
throw (IOException)e;
}
} finally {
safelyCloseStream(inputStream);
}
return result;
}
示例13: getEncoding
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
private static String getEncoding(HttpConnection c) throws IOException {
String enc = "ISO-8859-1";
String contentType = c.getHeaderField("Content-Type");
if (contentType != null) {
String prefix = "charset=";
int beginIndex = contentType.indexOf(prefix);
if (beginIndex != -1) {
beginIndex += prefix.length();
int endIndex = contentType.indexOf(';', beginIndex);
if (endIndex != -1) {
enc = contentType.substring(beginIndex, endIndex);
} else {
enc = contentType.substring(beginIndex);
}
}
}
return enc.trim();
}
示例14: postCellPosition
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
public void postCellPosition(String cellID, String mcc, String mnc, String lac, double latitude, double longitude, long ts) {
try {
final String url
= URL + "?method=celldb.addcell &" + ACCOUNT +
"&mcc=" + mcc +
"&mnc=" + mnc +
"&cellid=" + cellID +
"&lac=" + lac +
"&latitude=" + latitude +
"&longitude=" + longitude +
"&enduserid=" + controller.getLogin();
controller.log(url);
HttpConnection cnx = (HttpConnection) Connector.open(url);
InputStream is = cnx.openInputStream();
StringBuffer b = new StringBuffer();
int car;
while ((car = is.read()) != -1) {
b.append((char) car);
}
is.close();
cnx.close();
} catch (IOException e) {
controller.log(e.getClass().getName() + ": " + e.getMessage());
}
}
示例15: postCellPosition
import javax.microedition.io.HttpConnection; //导入依赖的package包/类
public void postCellPosition(String cellID, String mcc, String mnc, String lac, double latitude, double longitude, long ts) {
try {
final String url = URL + "measure/add" + KEY +
"&mcc=" + mcc +
"&mnc=" + mnc +
"&cellid=" + cellID +
"&lac=" + lac +
"&lat=" + latitude +
"&lon=" + longitude;
controller.log(url);
HttpConnection cnx = (HttpConnection) Connector.open(url);
InputStream is = cnx.openInputStream();
StringBuffer b = new StringBuffer();
int car;
while ((car = is.read()) != -1) {
b.append((char) car);
}
is.close();
cnx.close();
} catch (IOException e) {
controller.log(e.getClass().getName() + ": " + e.getMessage());
}
}