gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 22:21:43 24 4
gpt4 key购买 nike

如何创建最简单的 *(更少的代码行,更少的奇怪单词)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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com