c# - 如何创建支持 UTF-8 的最简单的 PHP Get API?

标签 c# .net php api utf-8

如何创建最简单的 *(更少的代码行,更少的奇怪单词)PHP Get API *(所以任何用 .Net C# 编写的程序都可以调用像 http://localhost/api.php?astring= 这样的 url your_utf-8_string&bstring=your_utf-8_string ) 是否支持 UTF-8?

我需要的是具有一个功能的 PHP API - 连接 2 个字符串,以便像这样的简单 .net 客户端能够使用它:

    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;
    }

最佳答案

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);
    }
}

关于c# - 如何创建支持 UTF-8 的最简单的 PHP Get API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2830765/

相关文章:

c# - 为什么 COM Interop 将 VB6 bool 值视为 C# 短整数?

.net - 带有受控自动换行的图形抽绳

php - yii向第三张表插入数据

c# - Azure 虚拟助手提示按钮

c# - 如何在 C# 中以像素级操作图像

c# - 我应该使用 C# 中的哪种只读、保留顺序的集合来支持枚举?

c# - 当服务器返回错误时,有什么方法可以使用 WebClient 访问响应主体?

php - 在 PHP 中经过一定时间后的 session_destroy()

php - 存储所有细节的所有数据更改(例如Stackoverflow)

c# - ReSharper:枚举器可能出现 NullReferenceException?