-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

3
  • i know $_FILES should return empty array i put it when i lost my mind, Why $_POST return empty array Commented Oct 24, 2017 at 7:13
  • finally i know the problem, i type https:// instead of http:// in my string , and it works Commented Oct 24, 2017 at 8: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 for his answer in thread 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 Commented Oct 24, 2017 at 11:11

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.