无法将'System.Net.FileWebRequest'强制转换为远程计算机上的'System.Net.HttpWebRequest',但可以在本地运行 [英] 'System.Net.FileWebRequest' can not be casted to 'System.Net.HttpWebRequest' on remote machine, but works locally

查看:71
本文介绍了无法将'System.Net.FileWebRequest'强制转换为远程计算机上的'System.Net.HttpWebRequest',但可以在本地运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从服务器尝试时出现错误(在服务器上部署了相同的代码):

I am getting the error when trying from a server (deployed the same code on the server):

无法将类型为"System.Net.FileWebRequest"的对象转换为类型为"System.Net.HttpWebRequest"

但是当我尝试在本地计算机上使用相同的代码时,它没有给出错误.

But when I am trying to use the same code from my local machine, it is not giving error.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

任何有想法的人怎么了?

Any idea guys what could be wrong?

推荐答案

传入的URI不是 http URI,它只是路径或文件 URI.确保URI以 http:开头.如果它是相对URI,则需要将其设为绝对.

The URI being passed in is not an http URI -- it's either just a path or a file URI. Ensure the URI starts with http:. If it's a relative URI, you'll need to make it absolute.

这篇关于无法将'System.Net.FileWebRequest'强制转换为远程计算机上的'System.Net.HttpWebRequest',但可以在本地运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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