本文整理汇总了Java中javax.microedition.io.HttpConnection.setRequestMethod方法的典型用法代码示例。如果您正苦于以下问题:Java HttpConnection.setRequestMethod方法的具体用法?Java HttpConnection.setRequestMethod怎么用?Java HttpConnection.setRequestMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.HttpConnection
的用法示例。
在下文中一共展示了HttpConnection.setRequestMethod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: getStream
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
public InputStream getStream() throws IOException {
try {
final HttpConnection connection = (HttpConnection)Connector.open(URI);
connection.setRequestMethod(HttpConnection.GET);
InputStream httpStream = connection.openInputStream();
//Buffer our stream, since reading small units at a time from the network
//increases the likelihood of network errors
return new BufferedInputStream(httpStream) {
/* (non-Javadoc)
* @see java.io.InputStream#close()
*/
public void close() throws IOException {
//Some platforms were having issues with the connection close semantics
//where it was supposed to close the connection when the stream was closed,
//so we'll go ahead and move this here.
connection.close();
super.close();
}
};
} catch(SecurityException se) {
if(this.listener != null) {
listener.onSecurityException(se);
}
throw new IOException("Couldn't retrieve data from " + this.getLocalURI() + " due to lack of permissions.");
}
}
示例3: 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));
}
示例4: findType
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
* 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;
}
示例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: getTime
import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
public long getTime() throws IOException {
HttpConnection conn = (HttpConnection) Connector.open(url);
try {
conn.setRequestMethod(method);
long time = conn.getDate();
if (time != 0) {
return time / 1000;
} else {
throw new RuntimeException("Server returned no valid date in http header");
}
} finally {
conn.close();
}
}
示例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: 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);
}
}