Reading a string echoed from PHP into java? -


i trying use following code retrieve response server echoed through php. string compare methods compareto() , (...).equals(..) not act when code executed. have tried sorts of options , i'm convinced in spite of appearing convert response string format, "responsetext" not have typical string properties. if have 3 string literal statements, 1 of echoed finduser.php. how can read java in way allow me determine contents of string trying here? have found lot of discussion needing create bufferedreader object, not understand how implement that. if please lay out steps me, appreciative.

 try {         httpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost(".../finduser.php");         httppost.setentity(new urlencodedformentity(namevaluepairs));         httpresponse response = httpclient.execute(httppost);         final string responsetext =  entityutils.tostring(response.getentity());           if(responsetext.compareto("not registered") == 0 || responsetext.compareto("error") == 0) {             log.i("kyle","true");           // display error message             textview loginerror = (textview)findviewbyid(r.id.loginerrormsg);             loginerror.setvisibility(view.visible);           loginerror.settext(responsetext);        }         else {             globalvars.username = useremail;             login.this.finish();             intent intent = new intent(login.this,purchase.class);             startactivity(intent);       }         catch(exception e) {log.e("log_tag", "error in http connection"+e.tostring());} 

}

if responsetext log message looks correct comparison methods returning false, have character set issue. there many cases of appears same character appearing @ different code points of different character sets.

the documentation entityutils.tostring() states when no character set specified, tries analyse entity or falls iso-8859-1.

utf-8 safe default use. try adding top of php script:

<?php     header('content-type: text/plain; charset=utf-8');  ?> 

entityutils should pick up, if not can pass "utf-8" tostring() method force use same character set.


Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -