Skip to content Skip to sidebar Skip to footer

Json Is Showing Error 403 While Trying To Fetch Data From Database In Android

I am making an android application regarding online shopping. I was properly able to fetch data and to insert data in the database with my android application till today. (From las

Solution 1:

Taking a hint from this post, I think you may need to set the User-Agent header in your JSON request. Try adding a line in JSONFunction.makeHttpRequest() before the call to execute() like:

httpPost.setHeader("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36");

or, on the line before calling setEntity() you could do something like:

para.add(new NameValuePair("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36"));

(Note: this user-agent string is just one I pulled from my browser. You can probably use one from any modern browser.)

This will make your REST service believe that the request is coming from a web browser. I suspect that is what may be causing the 403, i.e. that your web server doesn't know what kind of agent the request is coming from. As for why it just stopped working, perhaps the server where your PHP service is running was updated recently so that it won't accept requests where the user-agent is not declared.

Post a Comment for "Json Is Showing Error 403 While Trying To Fetch Data From Database In Android"