I trie to send some json data with android to a server. The server is raspberry pi connected in my local WI-FI. Everytime I try to send the data I get a connection refused in my debug output. But I can't figure out why.
This is my android method:
public void sendJson(View view){
String url = "http://192.168.0.5/control_center/functions/incomming.php";
TextView textView_result;
textView_result = (TextView) findViewById(R.id.textView_result);
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type" , "application/json");
JSONObject jsonObject = new JSONObject();
jsonObject.put("regid", "1234345893458435934kl34n543kl543öl53n4k5j43");
String json = jsonObject.toString();
StringEntity se = new StringEntity(json);
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
textView_result.setText(httpResponse.toString());
}catch(JSONException e){
e.printStackTrace();
}catch(UnsupportedEncodingException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}
And this is the php file on my server:
<?php
include('db_connect.php');
$db = new _DB_Connect();
$db->connect();
if(isset($_POST['regid'])){
$regid = $_POST['regid'];
$save_entry = "insert into gcm_users (gcm_regid) values ('$regid')";
mysql_query($save_entry) or die (mysql_error());
} else {
echo 'no data';
}
?>
Internet permission on android is given.
<uses-permission android:name="android.permission.Internet" />