-1

i am trying to make a simple code for bigger project that depends on sending data to php website , but the result always empty, The Problem is both return empty result , i print the response to a label but it returns empty arrays,

Xamarin Code is

private async void sendphp()
    {

        Uri uri = new Uri("http://example.com/iservices/send.php");
        var postData = new List<KeyValuePair<string, string>>
        {
            new KeyValuePair<string, string>("param1", "value"),
            new KeyValuePair<string, string>("param2", "value")
        };

        HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, uri);
        req.Content = new FormUrlEncodedContent(postData);

        HttpClient client = new HttpClient();
        var response = await client.SendAsync(req);

        var content = await response.Content.ReadAsStringAsync();
        lblInfo.Text = content;


    }

PHP Code is :

<?php 
 print_r($_POST);
 print_r($_FILES);
?>

The Problem is both return empty result , i print the response to a label but it returns empty arrays, i checked to server response it ok but the post is empty , why ??????? i spent 4 days trying many solution but all fails

  • i know $_FILES should return empty array i put it when i lost my mind, Why $_POST return empty array – Ahmed Saber Abdel-Qader Oct 24 '17 at 07:13
  • finally i know the problem, i type https:// instead of http:// in my string , and it works – Ahmed Saber Abdel-Qader Oct 24 '17 at 08:50
  • Now i can do it with PostAsync Aslo to send json format, just php like this $json = file_get_contents('php://input'); $obj = json_decode($json); print_r($obj); thanks [michael-sivolobov](https://stackoverflow.com/users/2261177/michael-sivolobov) for [his answer in thread](https://stackoverflow.com/questions/19004783/reading-json-post-using-php) and now i can read normal KeyvaluePair using SendAsync with HttpRequest i wil leave this to everyone whom facing the same problem , i collect answer from many places, and sorry for long text – Ahmed Saber Abdel-Qader Oct 24 '17 at 11:11

1 Answers1

0

finally i know the problem, the question of Tim_Kimp inspires me to look at the .htaccess on my server, i added .htaccess in that folder and it gives me response ( 404 file not found ), hopelessly i type https:// instead of http:// in my string , aaaaand it works the $_POST returns a result, can't believe it, i spent 4 days in harm ! so i suggest any one have the same issue should check .httaccess or server configuration and test on local server first