gpt4 book ai didi

c# - 在 C# 中发送 HTTP 请求失败

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

我在我的 chrome 中使用以下 URL,它工作正常: https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/62bea90c-9b0c-487b-8416-1a4d94772f99?subscription-key=29317e2237fb4b43a91959cadee6f143&staging=true&verbose=true&timezoneOffset=480&q=哪个国家获得2010年世界杯第一名

它返回如下所示的 json 字符串:

{
"query": "哪个国家获得2010年世界杯第一名",
"topScoringIntent": {
"intent": "Query",
"score": 0.9818858
},
"intents": [
{
"intent": "Query",
"score": 0.9818858
},
{
"intent": "None",
"score": 0.01755463
}
],
"entities": [
{
"entity": "2010年",
"type": "builtin.datetimeV2.daterange",
"startIndex": 6,
"endIndex": 10,
"resolution": {
"values": [
{
"timex": "2010",
"type": "daterange",
"start": "2010-01-01",
"end": "2011-01-01"
}
]
}
},
{
"entity": "2010",
"type": "builtin.number",
"startIndex": 6,
"endIndex": 9,
"resolution": {
"value": "2010"
}
},
{
"entity": "一",
"type": "builtin.number",
"startIndex": 15,
"endIndex": 15,
"resolution": {
"value": "1"
}
}
]
}

但是当我在 C# 中发送 URL 时,请看下面:

    private void button1_Click(object sender, EventArgs e)
{
string uri = txtURL.Text;
if (uri == null)
{
uri = @"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/62bea90c-9b0c-487b-8416-1a4d94772f99?subscription-key=29317e2237fb4b43a91959cadee6f143&staging=true&verbose=true&timezoneOffset=480&q=哪个国家获得2010年世界杯第一名";
}
var json_contents = new WebClient().DownloadString(uri); //exception thrown from this line
txtJson.Text = json_contents;
}

我收到一条错误消息:

'The path is not of a legal form.'

谁能告诉我原因以及如何在我的 C# 代码中解决这个问题

最佳答案

您需要在调用之前对 url 进行编码,因为它包含非 Ascii 字符。

您可以使用 HttpUtility.UrlEncode 或者您可以手动执行并引用链接

https://stackoverflow.com/a/8248262/6671466

可能会有帮助

关于c# - 在 C# 中发送 HTTP 请求失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50059679/

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