"Requesting");
int contentLength = -1;
if (con instanceof HttpConnection) {
HttpConnection httpCon = (HttpConnection) con;
if (post) {
httpCon.setRequestMethod("POST");
httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
}
httpCon.setRequestProperty("User-Agent", browser.userAgent);
httpCon.setRequestProperty("X-Screen-Width", ""+screen.getWidth());
httpCon.setRequestProperty("Connection", "Keep-Alive");
httpCon.setRequestProperty("Accept-Charset", "utf-8");
String cookie = browser.getCookies(url);
if (cookie != null) {
// System.out.println("Setting Cookie: " + cookie);
httpCon.setRequestProperty("Cookie", cookie);
}
if (post && requestData != null) {
OutputStream os = httpCon.openOutputStream();
os.write(requestData);
os.close();
// System.out.println("Postdata\n" + new String(requestData));
}
// System.out.println("receiving:");
contentLength = (int) httpCon.getLength();
int headerIndex = 0;
while (true){
String name = httpCon.getHeaderFieldKey(headerIndex);
if (name == null) {
break;
}
name = name.toLowerCase();
// System.out.println(name + ": " + httpCon.getHeaderField(headerIndex));
if ("content-type".equals(name)) {
String value = httpCon.getHeaderField(headerIndex);
if (value.indexOf("vnd.sun.j2me.app-descriptor") != -1) {
browser.platformRequest(url);
return;
}
int eq = value.indexOf ("harset=");
if (eq != -1) {
encoding = value.substring(eq + 7).trim();
}
} else if ("set-cookie".equals(name)) {
String cName = "";
String cValue = "";
String cHost = httpCon.getHost();
String cPath = "";
String cExpires = null;
String cSecure = null;
String[] parts = Util.split(
httpCon.getHeaderField(headerIndex), ';');
for (int i = 0; i < parts.length; i++){
String part = parts[i];
cut = part.indexOf('=');
if (cut == -1) {
continue;
}
String key = part.substring(0, cut).trim();
String value = part.substring(cut + 1).trim();
if (i == 0) {
cName = key;
cValue = value;
} else {
key = key.toLowerCase();
if ("host".equals(key)) {
cHost = value;
} else if ("path".equals(key)) {
cPath = value;
} else if ("expires".equals(key)) {
cExpires = value;
} else if ("secure".equals(key)) {
cSecure = value;
}
}
}
browser.setCookie(cHost, cPath, cName, cValue, cExpires, cSecure);
}
headerIndex++;
}
int responseCode = httpCon.getResponseCode();
// System.out.println("Response Code: " + httpCon.getResponseCode());
if (responseCode >= 300 && responseCode <= 310) {
String location = httpCon.getHeaderField("Location");
if (location != null) {
// System.out.println("Redirecting to: " + location);
screen.htmlWidget.setUrl(location);
browser.requestResource(screen.htmlWidget, method, location,
type, requestData);