Fixed it, please see the solution at the bottom
First of all sorry if this is a duplicate, trust me I tried searching if there was an existing answer...
OK so long story short I was following this tutorial (https://www.youtube.com/watch?v=wKwCgabRV2A). I had downloaded Wamp64 and set it up etc, set up my phpMyAdmin database and created the relevant table etc. however I didn't do anything more than set it up and run it.
I am attempting to use the following code inside of Android Studio to add the user's token ID to the database as follows:
final String token = FirebaseInstanceId.getInstance().getToken();
Log.d("TAG", token); //Just to confirm the token.
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.REGISTRATION_SCRIPT_ADDRESS,
new Response.Listener<String>(){
@Override
public void onResponse(String response){
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("user_token", token);
return params;
}
};
VolleyRequestManager.getManagerInstance(SplashActivity.this).addRequestToQueue(stringRequest);
The PHP file address is in the Config class:
public static final String REGISTRATION_SCRIPT_ADDRESS = "http://192.168.1.106/bbservice/server_token_insert.php";
However it doesn't work, and I simply get the following:
08-17 21:55:45.089 4206-4352/com.example.program E/Volley: [2745] BasicNetwork.performRequest: Unexpected response code 403 for http://192.168.1.106/bbservice/server_token_insert.php
08-17 21:55:45.102 4206-4352/com.example.program E/Volley: [2745] BasicNetwork.performRequest: Unexpected response code 403 for http://192.168.1.106/bbservice/server_token_insert.php
08-17 21:55:45.181 4206-4206/com.example.program W/System.err: com.android.volley.AuthFailureError
08-17 21:55:45.181 4206-4206/com.example.program W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:159)
08-17 21:55:45.181 4206-4206/com.example.program W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
With no changes made to the table at all.
Basically how can I solve the Code 403 problem? Is it something to do with my network permissions (I'm running the Wamp server on the same PC that I'm running Android Studio on)? If so what permissions do I need to change? Or is it a code problem?
Note: I am attempting to run this on my actual android device, not an emulator.
Any help is GREATLY appreciated!
Edit 1: The PHP script I call here is as follows:
<?php
require "server_connector.php";
$user_token = $_POST["user_token"];
$query = "INSERT INTO tokens VALUES('".$user_token."');";
mysqli_query($connection, $query);
mysqli_close($connection);
?>
Server Connector:
<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "bbservice";
$connection = mysqli_connect($host, $user, $password, $database);
if($connection){
echo "Connection Established";
}else{
echo "Connection Failed";
}
?>
These are both located within the C://Wamp64/www/BBService/ folder.
Edit 2:
Ok so now I'm getting still getting the same error after reinstalling wamp... I checked and confirmed the wamp apache service is the only service listening to Port 80 on my computer.
I have also attempted disabling Windows Firewall and it still did not work...
Edit 3: I tried another method to get this to work using OkHttp, using this method:
OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder().add("user_token", token).build();
Request request = new Request.Builder().url(Config.REGISTRATION_SCRIPT_ADDRESS).post(body).build();
try {
Response response = client.newCall(request).execute();
Log.d("SPLASH", "Executed request successfully.");
Log.d("SPLASH", "Response: " + response.body().string());
}catch(IOException ioex){
ioex.printStackTrace();
}
Aaaand I get the following:
Response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /bbservice/server_token_insert.php
this server.<br />
</p>
<address>Apache/2.4.18 (Win64) PHP/5.6.19 Server at 192.168.1.108 Port 80</address>
</body></html>
If I look at the wamp server information at localhost, it clearly states:
Apache/2.4.18 (Win64) PHP/5.6.19 - Port defined for Apache: 80 This error occurs with both Windows Firewall on and off...I may start ripping out hair soon...