我正在尝试使用HttpClient创建一个GET请求,请求的Uri如下:
http://test.com?action=enterorder&ordersource=acme&resid=urn%3Auuid%3A0c5eea50-9116-414e-8628-14b89849808d 正如您所看到的,resid参数被转义为%3A,即“:”字符。
当我在HttpClient请求中使用此Uri时,url变为:
http://test.com?action=enterorder&ordersource=acme&resid=urn:uuid:0c5eea50-9116-414e-8628-14b89849808d,由于服务器期望%3A,因此我收到了错误信息。
有人知道如何在发送请求时保留转义后的Uri吗?似乎HttpClient在发送字符串之前总是对字符进行解码。 以下是使用的代码:
Uri uri = new Uri("http://test.com?action=enterorder&ordersource=acme&resid=urn%3Auuid%3A0c5eea50-9116-414e-8628-14b89849808d");
using (HttpClient client = new HttpClient())
{
var resp = client.GetAsync(uri);
if (resp.Result.IsSuccessStatusCode)
{
var responseContent = resp.Result.Content;
string content = responseContent.ReadAsStringAsync().Result;
}
}
GetAsync
的字符串重载,它是否仍然会发生?client.GetAsync(uri.OriginalString);
- keyboardPuri
?你创建了它,但从未使用过。你尝试过client.GetAsync("http://test.com?action=enterorder&ordersource=acme&resid=urn%3Auuid%3A0c5eea50-9116-414e-8628-14b89849808d"
吗? - Peter Ritchie