小编man*_*u97的帖子

ASP.NET MVC 4 到 ASP.NET Web API - 错误:只允许使用“http”和“https”方案。参数名称:requestUri

ASP.NET MVC 在 TEST Server 中引发以下错误,我无法在 Developer 机器中重现该错误。

尝试从 MVC 连接到 WebAPI 服务并收到错误

只允许使用“http”和“https”方案。参数名称:requestUri

我无法从其他问题中得到答案,因为他们主要是在谈论 WCF 绑定。

代码:

var credentials = "username:Password";
var encoded = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials));
this.client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encoded);
System.Net.Http.HttpClient client = new HttpClient();
HttpResponseMessage response = client.GetAsync(URL).Result; 
Run Code Online (Sandbox Code Playgroud)

注意:通过浏览器访问 WebAPI URL 会返回数据。

asp.net asp.net-mvc-4 asp.net-web-api

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×1

asp.net-mvc-4 ×1

asp.net-web-api ×1