Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#HttpClient在POST请求期间截断URI_C#_Rest_Uwp_Httpclient - Fatal编程技术网

C#HttpClient在POST请求期间截断URI

C#HttpClient在POST请求期间截断URI,c#,rest,uwp,httpclient,C#,Rest,Uwp,Httpclient,我试图在C#UWP应用程序中向特定端点发出POST请求。我得到的结果就是主页上的HTML。在查看请求时,我指定的是整个端点,但在发出请求时,它只是命中主机(没有端点) 我正在尝试发布到:http://ip-address/api/devices/logs URI正在发布到:http://ip-address 守则: Uri requestUri = new Uri("http://ip-address/api/devices/logs"); var objClint = new System.N

我试图在C#UWP应用程序中向特定端点发出POST请求。我得到的结果就是主页上的HTML。在查看请求时,我指定的是整个端点,但在发出请求时,它只是命中主机(没有端点)

我正在尝试发布到:
http://ip-address/api/devices/logs
URI正在发布到:
http://ip-address

守则:

Uri requestUri = new Uri("http://ip-address/api/devices/logs");
var objClint = new System.Net.Http.HttpClient();
System.Net.Http.HttpResponseMessage respon = await objClint.PostAsync(requestUri , new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(text), System.Text.Encoding.UTF8, "application/json"));
string responJsonText = await respon.Content.ReadAsStringAsync();
我本打算返回POST请求的结果(如创建的对象),但我只是从主页/登录页获取HTML

我已尝试设置objClient的
基地址
,仅通过端点的其余部分,作为
PostAsync
中的参数通过整个端点,并添加
UriKind.Absolute

我真的不知道从这里该怎么办

如果我在同一个URI上运行
GetAsync
,它不会缩短请求URI并给出正确的响应


从这里我可以做什么?

当我测试您的代码片段时,它会按预期工作。你确定这条路线有邮局吗?可能代码没有截断URL,返回的只是重定向。我会先检查一下

无论哪种方式,如果您想尝试另一种也应该有效的方式,这里有一种使用相同依赖项生成请求的替代方法

var baseUri = new Uri("http: //ip-address/");
var route = "/api/devices/logs";
using (var objClint = new HttpClient())
{
      objClint.BaseAddress = baseUri;
      var respon = await objClint.PostAsync(route, new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(new { text = "text" }), System.Text.Encoding.UTF8, "application/json"));
}

你是怎么得出这个结论的?我想说,有90%的可能性它是发布到正确的URL,但你的服务器端路由没有工作的方式,你认为它应该。如果您有GET和POST端点(服务器端),请向我们展示它们的源代码。如果您没有,请向我们指出他们的文档。您的代码没有问题,应该可以正常工作。服务器返回了什么?