本文整理汇总了Java中javax.microedition.io.HttpConnection.HTTP_OK属性的典型用法代码示例。如果您正苦于以下问题:Java HttpConnection.HTTP_OK属性的具体用法?Java HttpConnection.HTTP_OK怎么用?Java HttpConnection.HTTP_OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.microedition.io.HttpConnection
的用法示例。
在下文中一共展示了HttpConnection.HTTP_OK属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findType
/**
* Finds the type of the content in this Invocation.
* <p>
* The calling thread blocks while the type is being determined.
* If a network access is needed there may be an associated delay.
*
* @return the content type.
* May be <code>null</code> if the type can not be determined.
*
* @exception IOException if access to the content fails
* @exception IllegalArgumentException if the content is accessed via
* the URL and the URL is invalid
* @exception SecurityException is thrown if access to the content
* is required and is not permitted
*/
String findType() throws IOException, SecurityException {
String type = null;
Connection conn = openPrim(true);
if (conn instanceof ContentConnection) {
if( conn instanceof HttpConnection ){
HttpConnection hc = (HttpConnection)conn;
hc.setRequestMethod(HttpConnection.HEAD);
// actual connection performed, some delay...
if (hc.getResponseCode() != HttpConnection.HTTP_OK)
return null;
}
type = ((ContentConnection)conn).getType();
conn.close();
if (type != null) {
// Check for and remove any parameters (rfc2616)
int ndx = type.indexOf(';');
if (ndx >= 0) {
type = type.substring(0, ndx);
}
type = type.trim();
if (type.length() == 0) {
type = null;
}
}
}
return type;
}
示例2: setURL
public void setURL(String host, String url) throws IOException {
closeStream();
conn = (HttpConnection) Connector.open("http://" + host + url, Connector.READ, true);
conn.setRequestMethod(HttpConnection.GET);
if (conn.getResponseCode() == HttpConnection.HTTP_OK) {
in = conn.openInputStream();
// Retrieve MIME type of the stream
contentType = conn.getHeaderField("Content-Type");
} else {
throw new IOException("Unexpected HTTP return: " + conn.getResponseCode());
}
}
示例3: urlToProperties
protected Properties urlToProperties(String url) throws IOException {
HttpConnection conn = (HttpConnection) Connector.open(url);
conn.setRequestProperty("user-agent", userAgent);
try {
int rc = conn.getResponseCode();
// If we get a wrong HTTP response code, we might as well just stop trying
if (rc != HttpConnection.HTTP_OK) {
if (Logger.BUILD_NOTICE) {
Logger.log(this + ".urlToProperties: Could not fetch " + url + " !", true);
}
cancel();
}
BufferedReader reader = new BufferedReader(conn.openInputStream());
{
String line;
Properties props = new Properties();
while ((line = reader.readLine()) != null) {
int p = line.indexOf(":");
if (p != -1) {
String name = line.substring(0, p);
String value = line.substring(p + 1).trim();
// Logger.log(name + " = " + value);
props.addProperty(name, value);
}
}
return props;
}
} finally {
conn.close();
}
}
示例4: fetch
public static byte[] fetch(String url) {
try {
HttpConnection c = (HttpConnection)Connector.open(url);
// Execute the request
int rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code " + rc + " when fetching " + url);
}
// Read the data
return readConnection(c);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例5: isOk
private static boolean isOk(int responseCode) {
return (responseCode == HttpConnection.HTTP_OK
|| responseCode == HttpConnection.HTTP_ACCEPTED
|| responseCode == HttpConnection.HTTP_CREATED);
}
示例6: run
/**
* {@inheritDoc}
*/
public void run() {
try {
// Visit the original download URL and read the JAD;
// if the MIDlet-Version has changed, invoke the callback.
String url = Build.DOWNLOAD_URL;
String applicationVersion = getApplicationVersion();
String userAgent = getUserAgent();
String language = getLanguage();
for (int redirectCount = 0; redirectCount < 10; redirectCount++) {
HttpConnection c = null;
InputStream s = null;
try {
c = connect(url);
c.setRequestMethod(HttpConnection.GET);
c.setRequestProperty("User-Agent", userAgent);
c.setRequestProperty("Accept-Language", language);
int responseCode = c.getResponseCode();
if (responseCode == HttpConnection.HTTP_MOVED_PERM
|| responseCode == HttpConnection.HTTP_MOVED_TEMP) {
String location = c.getHeaderField("Location");
if (location != null) {
url = location;
continue;
} else {
throw new IOException("Location header missing");
}
} else if (responseCode != HttpConnection.HTTP_OK) {
throw new IOException("Unexpected response code: " + responseCode);
}
s = c.openInputStream();
String enc = getEncoding(c);
Reader reader = new InputStreamReader(s, enc);
final String version = getMIDletVersion(reader);
if (version == null) {
throw new IOException("MIDlet-Version not found");
} else if (!version.equals(applicationVersion)) {
Application application = Application.getApplication();
application.invokeLater(new Runnable() {
public void run() {
mCallback.onUpdate(version);
}
});
} else {
// Already running latest version
}
} finally {
if (s != null) {
s.close();
}
if (c != null) {
c.close();
}
}
}
} catch (Exception e) {
System.out.println(e);
}
}
示例7: flush
public void flush() throws TTransportException {
// Extract request and reset buffer
byte[] data = requestBuffer_.toByteArray();
requestBuffer_.reset();
try {
// Create connection object
HttpConnection connection = (HttpConnection)Connector.open(url_);
// Timeouts, only if explicitly set
if (connectTimeout_ > 0) {
// XXX: not available
// connection.setConnectTimeout(connectTimeout_);
}
if (readTimeout_ > 0) {
// XXX: not available
// connection.setReadTimeout(readTimeout_);
}
// Make the request
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-thrift");
connection.setRequestProperty("Accept", "application/x-thrift");
connection.setRequestProperty("User-Agent", "JavaME/THttpClient");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Keep-Alive", "5000");
connection.setRequestProperty("Http-version", "HTTP/1.1");
connection.setRequestProperty("Cache-Control", "no-transform");
if (customHeaders_ != null) {
for (Enumeration e = customHeaders_.keys() ; e.hasMoreElements() ;) {
String key = (String)e.nextElement();
String value = (String)customHeaders_.get(key);
connection.setRequestProperty(key, value);
}
}
// connection.setDoOutput(true);
// connection.connect();
OutputStream os = connection.openOutputStream();
os.write(data);
os.close();
int responseCode = connection.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK) {
throw new TTransportException("HTTP Response code: " + responseCode);
}
// Read the responses
inputStream_ = connection.openInputStream();
} catch (IOException iox) {
System.out.println(iox.toString());
throw new TTransportException(iox);
}
}