最近在做项目,其中需要将一些js的http请求的代码改为C#形式的。js的代码如下
function getXMLHTTPObj()
{
var C = null;
try
{
C = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
C = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(sc)
{
C = null;
}
}
if( !C && typeof XMLHttpRequest != "undefined" )
{
C = new XMLHttpRequest();
}
return C;
}
function Send(Str,URL)
{
var Http = getXMLHTTPObj()
if( Http )
{
Http.open("POST",URL,false)
Http.send(Str)
return Http.responseText;
}
}
之后就可以再前台调用Send函数跳转页面,然后获得所请求的数据
但是现在改为C#,我使用了HttpWebRequest,
WebRequest request = WebRequest.Create("../IPC/PublicAPI.aspx?API=GetMaliListByPhaseId&phaseTaskId=" + Uri.EscapeDataString(phaseTaskId));
request.Method = "POST";
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string mailList = reader.ReadToEnd();
因为用的是相对路径,程序提示是不正确的uri格式。请问使用WebRequest(HttpWebRequest)能否使用相对路径跳到项目内的某个页面。
------解决方案--------------------
楼主需要看看页面传值方面的博客