复制内容Web API时出错 [英] error while copying content Web API

查看:79
本文介绍了复制内容Web API时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Http客户端投掷错误:复制内容时出错 


这是我的代码


            serverUrl = GetServerUri(serverUrl);

            HttpContent content = new StringContent(data.ToString(),Encoding.UTF8," application / json");

            HttpClient client = new HttpClient(new HttpClientHandler(){UseDefaultCredentials = true});

            client.BaseAddress = new Uri(serverUrl);

            content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(" application / json");

            client.DefaultRequestHeaders.Accept.Add(
$
         new MediaTypeWithQualityHeaderValue(" application / json"));

            var response = client.PostAsync(url,content).Result;

            return response.Content.ReadAsStringAsync()。Result;


我在root级别部署web api时工作正常。 喜欢:http:\\servername \ api \ control \ method


但是当我像这样部署web api时:   http:\\servername \\ \\ apiname \ api \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ b


解决方案

为什么不尝试发布异常消息?但请将您的帖子发布到以下论坛。


https://forums.asp.net/1246.aspx/1?Web+API



Http Client throwing error : error while copying content 

This is my code

            serverUrl = GetServerUri(serverUrl);
            HttpContent content = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
            HttpClient client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true });
            client.BaseAddress = new Uri(serverUrl);
            content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
            client.DefaultRequestHeaders.Accept.Add(
               new MediaTypeWithQualityHeaderValue("application/json"));
            var response = client.PostAsync(url, content).Result;
            return response.Content.ReadAsStringAsync().Result;

It works fine when i deploy web api in root level.  like : http:\\servername\api\controller\method

But when i deploy web api like this :  http:\\servername\apiname\api\controller\method

This throws this exception.

Any idea ? 

解决方案

Why don't you try posting the exception message? But make your post to the below forum.

https://forums.asp.net/1246.aspx/1?Web+API


这篇关于复制内容Web API时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆