From bead45360ff54c55b9a14126a93ffef0fc7d4681 Mon Sep 17 00:00:00 2001 From: Jesse Young Date: Tue, 13 Sep 2011 11:31:01 -0700 Subject: [PATCH] set phone number and api version as regular post fields instead of custom http headers --- server/php/KalSMS.php | 4 ++-- src/org/envaya/kalsms/HttpTask.java | 29 ++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/server/php/KalSMS.php b/server/php/KalSMS.php index 9e4ecee..5a68294 100755 --- a/server/php/KalSMS.php +++ b/server/php/KalSMS.php @@ -18,7 +18,7 @@ class KalSMS static function new_from_request() { - $version = @$_SERVER['HTTP_X_KALSMS_VERSION']; + $version = @$_POST['version']; return new KalSMS(); } @@ -56,7 +56,7 @@ class KalSMS function get_request_phone_number() { - return @$_SERVER['HTTP_X_KALSMS_PHONENUMBER']; + return @$_POST['phone_number']; } function is_validated_request($correct_password) diff --git a/src/org/envaya/kalsms/HttpTask.java b/src/org/envaya/kalsms/HttpTask.java index 56c374b..7ae3797 100755 --- a/src/org/envaya/kalsms/HttpTask.java +++ b/src/org/envaya/kalsms/HttpTask.java @@ -10,6 +10,7 @@ import java.io.InputStream; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.xml.parsers.DocumentBuilder; @@ -48,10 +49,10 @@ public class HttpTask extends AsyncTask return new DefaultHttpClient(httpParameters); } - private String getSignature(String url, BasicNameValuePair... params) + private String getSignature(String url, List params) { try { - Arrays.sort(params, new Comparator() { + Collections.sort(params, new Comparator() { public int compare(Object o1, Object o2) { return ((BasicNameValuePair)o1).getName().compareTo(((BasicNameValuePair)o2).getName()); @@ -97,13 +98,17 @@ public class HttpTask extends AsyncTask } HttpPost post = new HttpPost(url); - - post.setEntity(new UrlEncodedFormEntity(Arrays.asList(params))); - - String signature = this.getSignature(url, params); - post.setHeader("X-Kalsms-Version", "2"); - post.setHeader("X-Kalsms-PhoneNumber", app.getPhoneNumber()); + List paramList + = new ArrayList(Arrays.asList(params)); + + paramList.add(new BasicNameValuePair("version", "2")); + paramList.add(new BasicNameValuePair("phone_number", app.getPhoneNumber())); + + post.setEntity(new UrlEncodedFormEntity(paramList)); + + String signature = this.getSignature(url, paramList); + post.setHeader("X-Kalsms-Signature", signature); HttpClient client = getHttpClient(); @@ -126,11 +131,17 @@ public class HttpTask extends AsyncTask return null; } } - catch (Throwable ex) + catch (IOException ex) { app.logError("Error while contacting server", ex); return null; } + catch (Throwable ex) + { + app.logError("Unexpected error while contacting server", ex, true); + return null; + } + } protected String getDefaultToAddress()