PDA

View Full Version : Won't post the data to edit the text file :(



ZaSz
02-12-2010, 05:54 AM
try {
URL url;
URLConnection urlConnection;
DataOutputStream outStream;
DataInputStream inStream;

// Build request body
String body =
"script=" + URLEncoder.encode("zte", "UTF-8") +
"&action=" + URLEncoder.encode("update", "UTF-8") +
"&fish=" + URLEncoder.encode("3000", "UTF-8") +
"&item=" + URLEncoder.encode("sapp", "UTF-8") +
"&amount=" + URLEncoder.encode("1000", "UTF-8");

// Create connection
url = new URL("http://zaszmedia.com/cantsay/sad.php");
urlConnection = url.openConnection();
((HttpURLConnection)urlConnection).setRequestMetho d("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConnection.setRequestProperty("Content-Length", ""+ body.length());

// Create I/O streams
outStream = new DataOutputStream(urlConnection.getOutputStream());
inStream = new DataInputStream(urlConnection.getInputStream());

// Send request
outStream.writeBytes(body);
outStream.flush();
outStream.close();


// Close I/O streams
inStream.close();
outStream.close();
}
catch(Exception ex) {
System.out.println("Exception cought:\n"+ ex.toString());
}

Will NOT end up editing the text file on the server! Php code =


<?

$script = $_REQUEST['script'];
$action = $_REQUEST['action'];
$user = $_REQUEST['user'];
$updateitem = $_REQUEST['item'];
$upamount = $_REQUEST['amount'];
$minutes = $_REQUEST['mins'];
$hours = $_REQUEST['hours'];
$days = $_REQUEST['days'];
$weeks = $_REQUEST['weeks'];
$fish = $_REQUEST['fish'];

if(strtolower($script)=='zte'){
if(strtolower($action)=='load'){

} else if(strtolower($action)=='update'){
if(strtolower($action)=='update'){
$fp = fopen("./link.txt", "r+b");
// read the first line ...
$nr_inreg_arr = fscanf($fp, "%d\n");
// ... as an integer representing the number of entries in the log
$nr_inreg = $nr_inreg_arr[0]; // Fish Eaton
if($fish != ''){
$rez = sprintf("%08u\n", ($nr_inreg + $fish));
// ... write it back at the beginning of the log file
fseek($fp, 0, SEEK_SET);
fwrite($fp, $rez);
}
if($updateitem == 'sapp'){
$rez = sprintf("%08u\n", ($nr_inreg + $upamount));
// ... write it back at the beginning of the log file
fseek($fp, 9, SEEK_SET);
fwrite($fp, $rez);
}
fclose($fp);
}
}
}
?>

If I go to enter the stuff manually at http://zaszmedia.com/cantsay/sad.php?script=zte&action=update&fish=1000

It updates the text...

ZaSz
02-12-2010, 06:46 AM
Fixed, after a few different calling web pages methods, I found one that works.

Thanks to method and Wizzup? Who were on this page for over 10 mins, as I think they were trying to solve the problem then gave up. (I hope lol much love)