本文整理汇总了Java中javax.microedition.io.HttpConnection.getHeaderField方法的典型用法代码示例。如果您正苦于以下问题:Java HttpConnection.getHeaderField方法的具体用法?Java HttpConnection.getHeaderField怎么用?Java HttpConnection.getHeaderField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.HttpConnection
的用法示例。
在下文中一共展示了HttpConnection.getHeaderField方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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();
}
示例4: readCookies
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
* Read cookies from the HttpConnection and store them in the cookie jar.
*
* @param hcon HttpConnection object
* @throws IOException
*/
private void readCookies(HttpConnection hcon) throws IOException {
String headerName = hcon.getHeaderField(0);
// Loop through the headers, filtering "Set-Cookie" headers
for (int i = 0; headerName != null; i++) {
headerName = hcon.getHeaderFieldKey(i);
if (headerName != null && headerName.toLowerCase().equals("set-cookie")) {
String cookieContent = hcon.getHeaderField(i);
COOKIE_JAR.put(cookieContent);
}
}
}
示例5: setURL
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
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());
}
}
示例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);
//some J2ME devices such as Nokia send all the cookies in one
//header spereated by commas
if(name.equalsIgnoreCase("Set-Cookie")){
//it is not possible to simply tokenize on comma, because
//the expiration date of each cookie contains a comma, therefore
//we temporary remove this comma tokenize all the cookies and then
//fixing the comma in the expiration date
String cookies = "";
Vector v = StringUtil.tokenizeString(val, ';');
for (int j = 0; j < v.size(); j++) {
String keyval = (String) v.elementAt(j);
if(keyval.indexOf("expires") > -1){
keyval = StringUtil.replaceAll(keyval, ",", "@[email protected]");
}
cookies += keyval + ";";
}
cookies = cookies.substring(0, cookies.length() - 1);
if(cookies.indexOf(",") > -1){
Vector v2 = StringUtil.tokenizeString(cookies, ',');
for (int j = 0; j < v2.size(); j++) {
String value = (String) v2.elementAt(j);
value = StringUtil.replaceAll(value, "@[email protected]", ",");
r.addElement(value);
}
}
}else{
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: run
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
* {@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);
}
}
示例8: getHeaderHelper
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
* j2me often lowercases everything, so we need to try the "correct" name
* and the lowercase name.
*
* @param conn
* @param value
* @return
*/
private static String getHeaderHelper(HttpConnection conn, String value) throws IOException {
String ret = conn.getHeaderField(value);
return ret == null ? conn.getHeaderField(value.toLowerCase()) : ret;
}