last day (15 days later) » 

2:04 PM
0
A: JSON response from server different than expected

meda If I add this print_r($_GET); at the beginning of index.php I get in the verbose log You are not using GET you are using POST, so it should be print_r($_POST);. If you are not sure then use print_r($_REQUEST); You also echo all over your script I suggest you to build your array the way y...

 
I used print_r($_POST); too and I get the same response.Well the else should never be executed when sending from the app.
What should I modify in the app/server code to make it work ?
 
@BogdanDaniel you just need better debugging skills, to debug this remove everything and put <?php echo json_encode($_REQUEST);?> then log the response to your android app
 
I know ... As I said there I don't have experience with php. Thank you for helping me. I did as you said and the response that I get is [].
 
This means the app is not sending the post variables successfully, I need to see more
 
What else can I do to help you ?
 
2:04 PM
I see in your android logs the values are set right
 
Yes, so the problem must come from somewhere else
 
Daniel dont worry we gonna get this shit sorted out
<?php echo json_encode($_REQUEST);?>
Is this all you have in your php
 
and I added exit; after it
 
ok
<?php echo json_encode(array('test'=>123));?>
 
I receive in the app
{"test":123}
and the app is no longer crashing because of that json, is only loading the async task forever
 
2:19 PM
what you mean loading forever
 
I have onPostExecute
in which I have
protected void onPostExecute(JSONObject json) {
try {
if (json.getString(KEY_SUCCESS) != null) {
 
please post the asynctask
 
Here or in the post ?
private class ProcessLogin extends AsyncTask<String, Void, JSONObject> {

private ProgressDialog pDialog;

String email,password;

@Override
protected void onPreExecute() {
super.onPreExecute();

inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.pword);
email = inputEmail.getText().toString();
password = inputPassword.getText().toString();
pDialog = new ProgressDialog(Login.this);
pDialog.setTitle("Contacting Servers");
pDialog.setMessage("Logging in ...");
 
3:04 PM
we should first solve the json problem, because it's being executed before everything goes into the async
 
3:16 PM
public static String getJSONFromUrl(String url, List<NameValuePair> params){

	HttpClient httpClient = new DefaultHttpClient();
	HttpPost httpPost = new HttpPost(url);

	String jsonString = null;

	try {
		httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
		HttpResponse response = httpClient.execute(httpPost);
		HttpEntity respEntity = response.getEntity();

		if (respEntity != null) {
			InputStream inputStream =  respEntity.getContent();
			BufferedReader reader = new BufferedReader(new InputStreamReader(
@BogdanDaniel
try this
no wait
 
3:35 PM
show I try it ?
or wait ?
 
ok try it
but you need to change your methods to return a string
instead of jsonobject
 
which methods ?
ok, I'm changing the methods now
I changed almost everything
but how should I change the async task
with what should I replace json.getString(KEY_SUCCESS) ?
if (json.getString(KEY_SUCCESS) != null) {

String res = json.getString(KEY_SUCCESS);

if(Integer.parseInt(res) == 1){
pDialog.setMessage("Loading User Space");
pDialog.setTitle("Getting Data");
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
JSONObject json_user = json.getJSONObject("user");
/**
* Clear all previous data in SQlite database.
**/
UserFunctions logout = new UserFunctions();
logout.logoutUser(getApplicationContext());
db.addUser(json_user.getString(KEY_FIRSTNAME),json_user.getString(KEY_LASTNAME),json_user.getString(KEY_EMAIL),json_user.getString(KEY_USERNAM
There are too many to be change if I make it a String and I don't think I can do it, as I don't understand all the PHP that was going on
 
its not alot
 
yeah, I changed all of them
 
I hope you are keeping copies of working code, I dont want you to screw your projects
 
3:46 PM
except the async task
I did keep
How should I modify the async task ?
 
private class ProcessLogin extends AsyncTask < String, Void, String > {

	private ProgressDialog pDialog;

	String email, password;

	@Override
	protected void onPreExecute() {
		super.onPreExecute();

		inputEmail = (EditText) findViewById(R.id.email);
		inputPassword = (EditText) findViewById(R.id.pword);
		email = inputEmail.getText().toString();
		password = inputPassword.getText().toString();
		pDialog = new ProgressDialog(Login.this);
		pDialog.setTitle("Contacting Servers");
		pDialog.setMessage("Logging in ...");
like this
loginUser() user too, should return a string
sorry if I take some time to respond Im at work you know
 
I'll modify it now
 
ok let me know
 
I tested it though just with a verbose log
in the onPostExecute
and I get back from the server
05-14 16:48:32.507 8667-9125/name.company.nightasset V/askj﹕ <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
<b>Warning</b>: Unexpected character in input: ''' (ASCII=39) state=1 in <b>/home/a6109760/public_html/projectapp/index.php</b> on line <b>1</b><br />
<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' si
I did exactly the same as yours, but instead of Log.d I used Log.v, just to test it and I get that response back
 
it needs to log
json string =
json string = <your json>
you are clearly hitting a html page
 
3:53 PM
yeah.. that is the string that comes back
what do you mean by hitting a html page ?
 
<?php echo json_encode(array('test'=>123));?>
for this code
 
for that code I get back
{"test":123}
exactly as I did before
nothing changes
 
okay that is a good sign
<?php echo json_encode($_REQUEST);?>
replace with this now
 
for that one
I get
what I sent you in the previous message
the one that you said that I m hitting a html page
05-14 16:48:32.507 8667-9125/name.company.nightasset V/askj﹕ <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
<b>Warning</b>: Unexpected character in input: ''' (ASCII=39) state=1 in <b>/home/a6109760/public_html/projectapp/index.php</b> on line <b>1</b><br />
<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='000webhost.com'><font face='Arial' size='1' color='#00
 
ASCII=39
 
3:56 PM
Actually I get that twice
 
thats a single quote
 
05-14 16:56:17.087 8667-9100/name.company.nightasset V/askj﹕ <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
<b>Warning</b>: Unexpected character in input: ''' (ASCII=39) state=1 in <b>/home/a6109760/public_html/projectapp/index.php</b> on line <b>1</b><br />
<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' si
 
you have a syntax error somewhere
 
In my php file I have just this
<?php echo json_encode($_REQUEST);?>
and I m using the JSONParser that you gave me
found the problem for that long response
I missed ;
Now I get back this
05-14 16:58:10.757 8667-12308/name.company.nightasset V/askj﹕ []
05-14 16:58:10.757 8667-8667/name.company.nightasset V/askj﹕ []
I get the same thing as before
it's posted twice because I have Log.v in the JSONParser and in the async task
But it's still empty
 
ok try with post
<?php echo json_encode($_POST);?>
 
4:05 PM
same response
the JSONParser is probably still not sending data properly
It
it's just accessing the website
this is the url that I m connecting to clubproject.comxa.com/projectapp
the index.php is on that page
 
5:08 PM
@BogdanDaniel
 
<?php echo json_encode($_GET);?>
on your url add ?test=123
this is strange I dont see why it wouldnt post
check if get works
 
I did the first part and nothing changes
 
first part?
 
I'll test now ?test=123
yes
 
5:11 PM
http://clubproject.comxa.com/projectapp/index.php?test=123
in your script

<?php echo json_encode($_GET);?>
 
I get
{"test":"123"}
without the index part
you can try it too
to see that it s working
 
so you see this in your android log right
do you?
 
No
Just on the website
If I access that from the browser
the problem is that the android is not sending the tag and everything I think
It's just accessing the URL
 
add the query string its not working
so so so strange
http://clubproject.comxa.com/projectapp/index.php?test=123
make sure you add the index.php
I had this issue before where the server was not configured to default to index.php
 
I was saying
that
I just tested from the browser
I modified the app now
I don t have to include index in the path
and it's returning
{"test":"123"}
If I access that url through the app
What I was saying is that the JSONParser is not passing the parameters
It's simply accessing the url
 
5:24 PM
right And if you add index.php
does that make a difference for the app
not the browser
 
no it does not
I tested it with index in the path and without it
and it's working both ways
 

last day (15 days later) »