-3

My scripts have full access when I use my data plan and my app works fine, it is only when I switch to Wi-Fi that my scripts keep getting a 500 internal server error.

I am using php scripts where my app accesses this using:

    public JSONObject getHttpResponse(String domUrl){

    String parsedString = "";

    //Log.d("Tag Name", "gggg");
    try {

        URL url = new URL(domUrl);
        URLConnection conn = url.openConnection();

        HttpURLConnection httpConn = (HttpURLConnection) conn;
        httpConn.setAllowUserInteraction(false);
        httpConn.setInstanceFollowRedirects(true);
        httpConn.setRequestMethod("GET");
        httpConn.connect();

        InputStream is = httpConn.getInputStream();
        parsedString = convertinputStreamToString(is);

        httpConn.disconnect();
        //((HttpURLConnection) conn).disconnect();

        if(parsedString.length() > 0){
            return getJSONResponseObject(parsedString);
        }

        //Log.d("Tag Name xfgfgxfgxfg", parsedString);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

And my AndroidManifest.xml file contains this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxx.xxx" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Error i am getting:

java.io.FileNotFoundException: http://www.hugt.co.uk/getTopThreads.php?threadTitle=&threadCountry=&threadCategory=&threadSubCategory=
    02-15 10:28:10.675    6161-6184/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
    02-15 10:28:10.675    6161-6184/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.threadbump.trikampatel.threadbump.MainActivity.getHttpResponse(MainActivity.java:1220)
    02-15 10:28:10.675    6161-6184/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.threadbump.trikampatel.threadbump.MainActivity$17.run(MainActivity.java:1063)
    02-15 10:28:10.675    6161-6184/com.threadbump.trikampatel.threadbump W/System.err﹕ at java.lang.Thread.run(Thread.java:864)
    02-15 10:28:10.685    6161-6183/com.threadbump.trikampatel.threadbump W/System.err﹕ java.io.FileNotFoundException: http://www.hugt.co.uk/getFavourites.php?userID=49&threadTitle=&threadCountry=&threadCategory=&threadSubCategory=
    02-15 10:28:10.685    6161-6183/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
    02-15 10:28:10.685    6161-6183/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.threadbump.trikampatel.threadbump.MainActivity.getHttpResponse(MainActivity.java:1220)
    02-15 10:28:10.685    6161-6183/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.threadbump.trikampatel.threadbump.MainActivity$16.run(MainActivity.java:1009)
    02-15 10:28:10.685    6161-6183/com.threadbump.trikampatel.threadbump W/System.err﹕ at java.lang.Thread.run(Thread.java:864)
    02-15 10:28:10.685    6161-6182/com.threadbump.trikampatel.threadbump W/System.err﹕ java.io.FileNotFoundException: http://www.hugt.co.uk/getThread.php?threadTitle=&threadCountry=&threadCategory=&threadSubCategory=
    02-15 10:28:10.685    6161-6182/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
    02-15 10:28:10.685    6161-6182/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.threadbump.trikampatel.threadbump.MainActivity.getHttpResponse(MainActivity.java:1220)
    02-15 10:28:10.685    6161-6182/com.threadbump.trikampatel.threadbump W/System.err﹕ at com.threadbump.trikampatel.threadbump.MainActivity$12.run(MainActivity.java:714)
    02-15 10:28:10.685    6161-6182/com.threadbump.trikampatel.threadbump W/System.err﹕ at java.lang.Thread.run(Thread.java:864)

Could someone please advise?

redoc01
  • 2,107
  • 5
  • 32
  • 64
  • Probably due to all params are empty in URL `threadTitle=&threadCountry=&threadCategory=&threadSubCategory=` – ρяσѕρєя K Feb 15 '16 at 10:45
  • @ρяσѕρєяK, thanks for replying, but the scripts work fine when using my internet data plan. – redoc01 Feb 15 '16 at 10:47
  • Could this be to do with the server i am hosting with? – redoc01 Feb 15 '16 at 10:48
  • but on browser im also getting 500 error when using [http://www.hugt.co.uk/getFavourites.php?userID=49&threadTitle=&threadCountry=&threadCategory=&threadSubCategory=](http://www.hugt.co.uk/getFavourites.php?userID=49&threadTitle=&threadCountry=&threadCategory=&threadSubCategory=) url – ρяσѕρєя K Feb 15 '16 at 10:49
  • Yes i know, if you are using wireless thats what you get, but when using internet data plan the script in browser works, thats what i find wierd – redoc01 Feb 15 '16 at 10:50

1 Answers1

0

I had a similiar problem.

Adding this line

   urlConnection.setRequestProperty("Accept-Encoding", "identity");

Setting the Accept-Encoding request header explicitly disables automatic decompression and leaves the response headers intact; callers must handle decompression as needed, according to the Content-Encoding header of the response. Via the android HttpUrlconnection reference http://developer.android.com/reference/java/net/HttpURLConnection.html

Watson
  • 3
  • 1
  • 3
  • Still no luck, thanks for replying, could this be to do with setting on server host? – redoc01 Feb 15 '16 at 11:03
  • Hi, were you able to fix it? I don't think it is down to your server host, I think it has something to do with your requests – Watson Feb 16 '16 at 23:06