tags:

views:

44

answers:

2

How to create simpliest *(less lines of code, less strange words) PHP Get API *(so any programm made in .Net C# could call url like http://localhost/api.php?astring=your_utf-8_string&bstring=your_utf-8_string ) with UTF-8 support?

What I need Is PHP API with one function - concatinate 2 strings so that a simple .net client like this would be able to use it:

    public string setStream(string astring, string bstring)
    {
string newAstring =Uri.EscapeDataString(astring);
string newBstring = Uri.EscapeDataString(bstring);
        WebClient client = new WebClient();
        var result = client.DownloadString(("http://localhost/api.php?" + string.Format("astring={0}&bstring={1}", newAstring, newBstring)).ToString());
        return result;
    }
+2  A: 
public string SetStream(string astring, string bstring)
{
    using (var client = new WebClient())
    {
        var values = new NameValueCollection() {
            "astring", astring,
            "bstring", bstring
        };
        var result = client.UploadValues(
            "http://localhost/api.php", 
            "GET",
            values
        );
        return Encoding.Default.GetString(result);
    }
}
Darin Dimitrov
+2  A: 

Dunno if I'm missing something, but:

<?php

function concatinateStrigs($a, $b){
    return $a . $b;
}

echo concatinateStrigs($_GET['astring'], $_GET['bstring']);

?>
Indrek