本文整理汇总了Java中javax.microedition.io.HttpConnection.setRequestProperty方法的典型用法代码示例。如果您正苦于以下问题:Java HttpConnection.setRequestProperty方法的具体用法?Java HttpConnection.setRequestProperty怎么用?Java HttpConnection.setRequestProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.HttpConnection
的用法示例。
在下文中一共展示了HttpConnection.setRequestProperty方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:hprose,项目名称:hprose-j2me,代码行数:19,代码来源:HproseHttpClient.java示例2: 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;
}
开发者ID:hprose,项目名称:hprose-j2me,代码行数:19,代码来源:HproseHttpClient.java示例3: getOutputStream
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
protected OutputStream getOutputStream(Object context) throws IOException {
HttpConnection conn = (HttpConnection) context;
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("Content-Type", "application/hprose");
OutputStream ostream = conn.openOutputStream();
return ostream;
}
开发者ID:hprose,项目名称:hprose-j2me,代码行数:8,代码来源:HproseHttpClient.java示例4: getConnection
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
*
* @return
* @throws IOException
*/
private HttpConnection getConnection() throws IOException {
try {
HttpConnection conn = (HttpConnection) Connector.open(this.getUrl());
if (conn == null)
throw new RuntimeException("Null conn in getConnection()");
HttpRequestProperties requestProps = this.getRequestProperties();
if (requestProps == null) {
throw new RuntimeException("Null message.getRequestProperties() in getConnection()");
}
requestProps.configureConnection(conn);
//Retrieve either the response auth header, or the cached guess
String authorization = this.getAuthString();
if(authorization != null) {
conn.setRequestProperty("Authorization", authorization);
}
return conn;
} catch(SecurityException se) {
if(this.listener != null) {
listener.onSecurityException(se);
}
throw new IOException("Couldn't retrieve data from " + this.getUrl() + " due to lack of permissions.");
}
}
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:32,代码来源:AuthenticatedHttpTransportMessage.java示例5: getConnection
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
* @param url
* @return
* @throws IOException
*/
private HttpConnection getConnection(String connectionMethod) throws IOException {
String url = this.getUrl();
//Need to add some URL args if we aren't authenticating
if(this.authenticator == null) {
String newArg = "authtype=noauth";
//See if we have any existing args
if(url.indexOf("?") != -1) {
//add to the list
url = url + "&" + newArg;
} else {
//Add a param list
url = url + "?" + newArg;
}
}
HttpConnection conn = (HttpConnection) Connector.open(url);
if (conn == null) {
throw new RuntimeException("Null conn in getConnection()");
}
HttpRequestProperties requestProps = this.getRequestProperties();
if (requestProps == null) {
throw new RuntimeException("Null message.getRequestProperties() in getConnection()");
}
//Retrieve either the response auth header, or the cached guess
String authorization = this.getAuthString();
if(authorization != null) {
conn.setRequestProperty("Authorization", authorization);
}
requestProps.configureConnection(conn);
return conn;
}
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:45,代码来源:SimpleHttpTransportMessage.java示例6: configureConnection
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
public void configureConnection(HttpConnection conn) throws IOException {
conn.setRequestMethod(requestMethod);
for(Enumeration en = properties.keys() ; en.hasMoreElements() ;) {
String key = (String)en.nextElement();
String val = properties.get(key);
conn.setRequestProperty(key, val);
}
conn.setRequestProperty("Date", DateUtils.formatDateTime(new Date(), DateUtils.FORMAT_TIMESTAMP_HTTP));
}
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:13,代码来源:HttpRequestProperties.java示例7: writeCookies
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
* Take cookies from the cookie jar and write them as request propreties
* in the HttpConnection.
*
* @param hcon HttpConnection object
* @throws IOException
*/
private void writeCookies(HttpConnection hcon) throws IOException {
String cookieHeader = COOKIE_JAR.getCookieHeader();
if (cookieHeader == null) {
return;
}
hcon.setRequestProperty("Cookie", cookieHeader);
}
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:15,代码来源:HttpClient.java示例8: urlToProperties
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
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();
}
}
开发者ID:fclairamb,项目名称:tc65lib,代码行数:34,代码来源:AutoUpdater.java示例9: writePostData
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
private static void writePostData(HttpConnection connection, byte[] data) throws IOException {
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
OutputStream requestOutput = connection.openOutputStream();
requestOutput.write(data);
requestOutput.close();
}
开发者ID:yanex,项目名称:vika,代码行数:7,代码来源:HTTPMethods.java示例10: 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);
}
}
开发者ID:google,项目名称:google-authenticator,代码行数:63,代码来源:UpdateTask.java示例11: flush
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
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);
}
}
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:59,代码来源:THttpClient.java本文标签属性:
示例:示例英文
代码:代码零九
java:java自行车
HttpConnection:httpconnection请求
setRequestProperty:setRequestProperty