10-22-2012 05:53 AM
10-22-2012 06:01 AM
10-22-2012 06:11 AM
10-22-2012 06:18 AM
Hi
Pleas try this code. put your username password value as a parameter.
public static boolean useraccount(String username,String password)
{
boolean ret = false;
InputStream inputStream = null;
HttpConnection httpConnection = null;
try
{
StringBuffer returnStringBuffer = new StringBuffer();
String returnString = new String();
String desiredEncoding = "ISO-8859-1";
URLEncodedPostData params = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHAR SET, true);
params.append("username", username);
params.append("password", password);
String url = "<YOUR URL>" + params.toString();
//Connecting to Server
httpConnection = (HttpConnection)Connector.open(url);
inputStream = httpConnection.openDataInputStream();
if(httpConnection.getResponseCode() == HttpConnection.HTTP_OK)
{
int ch;
//Process Response
// check header field for a specific encoding
String contenttype = httpConnection.getHeaderField("Content-Type");
if (contenttype != null)
{
contenttype = contenttype.toUpperCase();
if (contenttype.indexOf("UTF-8") != -1)
{
desiredEncoding = "UTF-8";
}
}
// get an inputstreamreader to handle utf-8 data
InputStreamReader isr = new InputStreamReader(inputStream,desiredEncoding);
while ((ch = isr.read()) != -1)
{
returnStringBuffer.append((char) ch);
}
inputStream.close();
httpConnection.close();
inputStream = null;
httpConnection = null;
returnString = returnStringBuffer.toString();
// examine return string
if (returnString.indexOf("SUCCESS") != -1)
{
ret = true;
}
return ret;
}
inputStream.close();
httpConnection.close();
inputStream = null;
httpConnection = null;
//Bad Transaction.
return ret;
}
catch (Exception e)
{
System.out.println("Error occurred in ProcessTransaction(,)\n" + e.toString());
return ret;
}
finally
{
try
{
if (inputStream != null)
inputStream.close();
if (httpConnection != null)
httpConnection.close();
}
catch (Exception ee)
{
}
}
}
Thanks
Pawan
10-22-2012 10:05 AM
10-22-2012 10:06 AM
10-22-2012 10:09 AM
10-22-2012 10:12 AM
10-22-2012 10:13 AM
10-22-2012 10:18 AM
Oloruntoba wrote:
Yes... "http://www.onadabayi.x10.mx/test.phpusername=daniel&password=daniel"
This is not the same as sending a POST request with username/password, just saying.
If your webservice requires this format a simple GET would be sufficient.