I have a Class, what send a Http Request to a Server. In this class i create a timestamp. The variable for hour, minute... is correct and fill with the correct variable. But when i create my timestamp variable it gives an exeption, but the massage come not in the log cat and i dont know why.
My Code:
public String GetData(String reqUrl) {
String response = null;
try {
String tag [] = {"Sat", "Sun", "Mon", "tue", "Wed", "Thu", "Fri"};
String monat [] = {"Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec"};
Calendar cal = new GregorianCalendar();
cal.setTime( new Date() );
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int year = cal.get(Calendar.YEAR);
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
String timestamp = tag[dayOfWeek] + ", " + dayOfMonth + " " + monat[month] + " " + year + " " + hourOfDay + ":" + minute + ":" + second + " " + "GMT";
String timeAndAppID = HttpHandler.LoginParams.appid + timestamp;
String hash = getMD5EncryptedString(timeAndAppID);
URL url = new URL(reqUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Pragma", "no-cache");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Cache-Control", "no-cache");
conn.setRequestProperty("WWSVC-TS", timestamp);
conn.setRequestProperty("WWSVC-HASH", hash);
conn.connect();
// read the response
InputStream in = new BufferedInputStream(conn.getInputStream());
response = convertStreamToString(in);
} catch (MalformedURLException e) {
Log.e(TAG, "MalformedURLException: " + e.getMessage());
} catch (ProtocolException e) {
Log.e(TAG, "ProtocolException: " + e.getMessage());
} catch (IOException e) {
Log.e(TAG, "IOException: " + e.getMessage());
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
return response;
}