mysql - Access forbidden when making request to PHP script from Android device -


while trying build first app communicates remote server files trying access php file (with hardcoded data) on local server android app. problem php file returning xml data , not json have put

header('content-type: application/json; charset=utf-8')

to make sure return json no use. below code of andoroid app , php file. can please ? have put log cat shows bunch of xml tags not data

activity code snippet

        string responsestring;         responsestring =    com.rrdtech.example.generic.genericutility.getresponse(url_all_products);         log.i("inside doinbg=",responsestring); 

getresponse (url) code below

public static string getresponse (string url) {     httpentity entity = null;     stringbuilder sb = null;     try     {         httpclient httpclient = new defaulthttpclient();         httpget httppost = new httpget(url);         log.e("log_tag_htppost", httppost.tostring());         httpresponse response = httpclient.execute(httppost);         entity = response.getentity();         inputstream = entity.getcontent();         log.e("log_tag", "after input stream");         bufferedreader reader = new bufferedreader(new inputstreamreader(is,"iso-8859-1"),8);         sb = new stringbuilder();         sb.append(reader.readline() + "\n");         string line="0";         while ((line = reader.readline()) != null)         {             sb.append(line + "\n");         }         is.close();     }catch(exception e)     {         log.e("log_tag", "error in http connection"+e.tostring());     }     return sb.tostring(); } 

log cat values below ... have print response stirng tag doinbg

 11-27 14:40:18.058: i/dbtest2mainscreen(7476): clicked on view products  11-27 14:40:18.150: e/log_tag_htppost(7476):                                                                                org.apache.http.client.methods.httpget@428bee98  11-27 14:40:18.710: e/log_tag(7476): after input stream 11-27 14:40:18.789: i/inside doinbg=(7476): <?xml version="1.0" encoding="utf-8"?>     11-27 14:40:18.789: i/inside doinbg=(7476): <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"        11-27 14:40:18.789: i/inside doinbg=(7476):   "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">   11-27 14:40:18.789: i/inside doinbg=(7476): <html xmlns="http://www.w3.org         /1999/xhtml" lang="en" xml:lang="en">    11-27 14:40:18.789: i/inside doinbg=(7476): <head>    11-27 14:40:18.789: i/inside doinbg=(7476): <title>access forbidden!</title>   11-27 14:40:18.789: i/inside doinbg=(7476): <link rev="made" href="mailto:you@example.com" />   11-27 14:40:18.789: i/inside doinbg=(7476): <style type="text/css"><!--/*--><![cdata[/*><!--*/    11-27 14:40:18.789: i/inside doinbg=(7476):     body { color: #000000; background-color: #ffffff; }   11-27 14:40:18.789: i/inside doinbg=(7476):     a:link { color: #0000cc; }   11-27 14:40:18.789: i/inside doinbg=(7476):     p, address {margin-left: 3em;}   11-27 14:40:18.789: i/inside doinbg=(7476):     span {font-size: smaller;}    11-27 14:40:18.789: i/inside doinbg=(7476): /*]]>*/--></style>    11-27 14:40:18.789: i/inside doinbg=(7476): </head>   11-27 14:40:18.789: i/inside doinbg=(7476): <body>   11-27 14:40:18.789: i/inside doinbg=(7476): <h1>access forbidden!</h1>    11-27 14:40:18.789: i/inside doinbg=(7476): <p>    11-27 14:40:18.789: i/inside doinbg=(7476):      11-27 14:40:18.789: i/inside doinbg=(7476):     </p><hr />   11-27 14:40:18.789: i/inside doinbg=(7476):     <p style="margin-left: 2.6em;       font-size: 1.2em; color: red;">new xampp security concept:</p>   11-27 14:40:18.789: i/inside doinbg=(7476):     <p>access requested object available local network.</p>    11-27 14:40:18.789: i/inside doinbg=(7476):     <p>this setting can configured in file &quot;httpd-xampp.conf&quot;.</p>   11-27 14:40:18.789: i/inside doinbg=(7476):     <hr /><p>     11-27 14:40:18.789: i/inside doinbg=(7476):        11-27 14:40:18.789: i/inside doinbg=(7476): </p>    11-27 14:40:18.789: i/inside doinbg=(7476): <p>      11-27 14:40:18.789: i/inside doinbg=(7476): if think server error,  please contact       11-27 14:40:18.789: i/inside doinbg=(7476): < href="mailto:you@example.com">webmaster</a>.     11-27 14:40:18.789: i/inside doinbg=(7476): </p>     11-27 14:40:18.789: i/inside doinbg=(7476): <h2>error 403</h2>     11-27 14:40:18.789: i/inside doinbg=(7476): <address>     11-27 14:40:18.789: i/inside doinbg=(7476):   <a href="/">192.168.1.101</a><br />     11-27 14:40:18.789: i/inside doinbg=(7476):   <span>apache/2.4.10 (unix)  openssl/1.0.1i php/5.5.15 mod_perl/2.0.8-dev perl/v5.16.3</span>       11-27 14:40:18.789: i/inside doinbg=(7476): </address>     11-27 14:40:18.789: i/inside doinbg=(7476): </body>      11-27 14:40:18.789: i/inside doinbg=(7476): </html> 

below json.php

<?php header('content-type: application/json; charset=utf-8');   $response = array(); $response["products"] = array();  $product = array();     $product["pid"] = "1";     $product["name"] = "iphone 4s";     $product["price"] = "300.00";     $product["created_at"] = "2012-04-29 02:04:02";     $product["updated_at"] = "0000-00-00 00:00:00";  array_push($response["products"], $product); $response["success"] = 1;  echo json_encode($response);  ?> 

new json parser class.....

// request method             defaulthttpclient httpclient = new defaulthttpclient();             string paramstring = urlencodedutils.format(params, "utf-8");             url += "?" + paramstring;             httpget httpget = new httpget(url);              httpresponse httpresponse = httpclient.execute(httpget);            // json_string = getjsonstring(httpresponse);            // log.i("calling method =","getjsonstring");            // log.i("json_string=",json_string);             httpentity httpentity = httpresponse.getentity();             //is = httpentity.getcontent();             if (httpentity != null)             {                 = httpentity.getcontent();                 string response1= is.tostring();                 log.i("httpresponse",response1);             }         }                } catch (unsupportedencodingexception e) {         e.printstacktrace();     } catch (clientprotocolexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }      try {         bufferedreader reader = new bufferedreader(new inputstreamreader(                 is, "iso-8859-1"), 8);         stringbuilder sb = new stringbuilder();         string line = null;         while ((line = reader.readline()) != null) {             sb.append(line + "\n");         }         is.close();         json = sb.tostring();     } catch (exception e) {         log.e("buffer error", "error converting result " + e.tostring());     }      // try parse string json object     try {         jobj = new jsonobject(json);     } catch (jsonexception e) {         log.e("json parser", "error parsing data " + e.tostring());     }      // return json string      return jobj; 

it's not xml. it's html error. , says:

access requested object available local network 

so should configure server properly.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -