public void Validate(String postStr) {
final List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>();
nameValuePairs.add(new BasicNameValuePair("data", postStr));
Runnable r = new Runnable() {
public void run() {
postData("https://www.dummydomain.com/api.php?f=validate", nameValuePairs);
}
};
BA.submitRunnable(r, this, 0);
}
private void postData(String url, List<BasicNameValuePair> nameValuePairs) {
if (BA.debugMode == true) { BA.Log("URL:" + url); }
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
if (nameValuePairs != null) {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
for (BasicNameValuePair pair : nameValuePairs) {
if (BA.debugMode == true) { BA.Log("NAME: " + pair.getName() + " => VALUE: " + pair.getValue()); }
}
}
if (BA.debugMode == true) { BA.Log("execute..."); }
HttpResponse response = httpclient.execute(httppost);
if (BA.debugMode == true) { BA.Log("Read..."); }
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String body = "";
String line = "";
while ((line = rd.readLine()) != null) {
body = body + line;
}
if (BA.debugMode == true) { BA.Log("BODY:"+body); }
if (url.contains("?f=validate") == true) {
if (thisBA.subExists(thisEventName + "_validationresponse")) {
BA.Log("Attempting to raiseevent..." + thisEventName + "_validationresponse");
thisBA.raiseEventFromDifferentThread(MyDummyClass.this, MyDummyClass.this, 0, thisEventName + "_validationresponse", true, new Object[] { body });
}
} else if (url.contains("?f=otherrequest") == true) {
if (thisBA.subExists(thisEventName + "_otherrequestresponse")) {
BA.Log("Attempting to raiseevent..." + thisEventName + "_otherrequestresponse");
thisBA.raiseEventFromDifferentThread(MyDummyClass.this, MyDummyClass.this, 0, thisEventName + "_otherrequestresponse", true, new Object[] { body });
}
}
if (BA.debugMode == true) { BA.Log(body); }
} catch (ClientProtocolException e) {
if (thisBA.subExists(thisEventName + "_validationerror")) {
BA.Log("Attempting to raiseevent..." + thisEventName + "_validationerror");
thisBA.raiseEventFromDifferentThread(MyDummyClass.this, MyDummyClass.this, 0, thisEventName + "_validationerror", true, new Object[] { e.getMessage() });
}
if (BA.debugMode == true) { BA.Log(e.getMessage()); }
} catch (IOException e) {
if (thisBA.subExists(thisEventName + "_validationerror")) {
BA.Log("Attempting to raiseevent..." + thisEventName + "_validationerror");
thisBA.raiseEventFromDifferentThread(MyDummyClass.this, MyDummyClass.this, 0, thisEventName + "_validationerror", true, new Object[] { e.getMessage() });
}
if (BA.debugMode == true) { BA.Log(e.getMessage()); }
}
}