In my code, sending a request to an http server, I've to add some params/values via GET method, but I noticed that all will works only by formating my http request (for example replacing 'space' with '%20'). My question: Exists an UrlEncoding method? Have I to define any HttpConnection's property.
Thanx in advance.
Marco
HttpConnection http = null;
InputStream iStr = null;
String str = null;
boolean ret = false;
if (c == cmdExit) {
destroyApp(false);
notifyDestroyed();
}
if (c == cmdTest) {
if (txt.getString() != null)
System.out.print(txt.getString());
try {
String formatQuery= txt.getString();
http = (HttpConnection) Connector.open(
"http://XXXXXXX/J2meServer/nonQuery.aspx?sql=" +
formatQuery(txt.getString()));
iStr = http.openInputStream();
String msg=new String("");
msg=processServerResponse(http, iStr);
private String formatQuery (String oldQuery)
{
String newQuery=new String(oldQuery.trim());
while (newQuery.indexOf(' ')!=-1)
{
int i=newQuery.indexOf(' ');
System.out.print("\n"+newQuery);
newQuery=newQuery.substring(0,i)+"%20"+newQuery.substring(i+1, newQuery.length());
}
return newQuery;
}
