php在asp.net中的应用

php在asp.net中的应用,php,asp.net,Php,Asp.net,asp.net语言中的等效代码是什么 <?php $ch = curl_init("http://irnafiarco.com/queue"); $request["queue"] = file_get_contents("/path_to_my_xml_file/my_xml_file.xml"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt(

asp.net语言中的等效代码是什么

<?php
$ch = curl_init("http://irnafiarco.com/queue");
$request["queue"] = file_get_contents("/path_to_my_xml_file/my_xml_file.xml");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
curl_close ($ch);
echo $response;
?>

在一个获取requst xml文件和saver xml文件的侦听器中。

看一看,WebProxy与您所追求的内容是内联的

WebRequest request = WebRequest.Create(url);
request.Proxy = new WebProxy("http://blahblahblah", true)
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// handle response here
尽管如此,也可能与您的实现无关

使用这些方法获取XML的示例比比皆是,例如:

System.Net.HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create("yourURL.xml");
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
webRequest.Accept = "text/xml";
System.Net.HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
System.IO.Stream responseStream = webResponse.GetResponseStream();
System.Xml.XmlTextReader reader = new XmlTextReader(responseStream);
//Do something meaningful with the reader here
reader.Close();
webResponse.Close();
使用,这将是基本代码

   var req = WebRequest.Create(@"http://irnafiarco.com/queue"))

   // prepare the request
   req.ContentType = "application/x-www-form-urlencoded";
   req.Method = "POST";

   // push the file contents into request body
   var data = "queue=" + System.IO.File.OpenText(filePath).ReadToEnd();
   var bytes = System.Text.Encoding.Ascii.GetBytes(data );  
    request.ContentLength = bytes.Length;
   var rs = req.GetRequestStream();
   rs.Write(bytes, 0, bytes.Length); 
   rs.Close ();

   // get the response
   var resp = req.GetResponse();
   var sr = new System.IO.StreamReader(resp.GetResponseStream());
   var result = sr.ReadToEnd();
免责声明:未经测试的代码

编辑
添加了我在初稿中遗漏的post参数名称(“队列”)。还为请求添加了内容长度。这段代码应该让你开始。基本思想是您需要模拟由PHP代码生成的精确post请求。使用诸如FF上的Fiddler/Firebug之类的工具来检查和比较来自PHP和.NET代码的请求/响应


此外,我怀疑PHP代码可能会生成内容类型为
multipart/formdata
的请求。然而,我相信服务器也应该能够支持带有
应用程序/x-www-form-urlencoded
的帖子正文(因为我们在正文中只有一个参数),但如果它不起作用,您必须将帖子正文生成为
多部分/表单数据
,那么它就不会太复杂了。请看这个问题,其中已接受的答案给出了相同的示例代码:

那么,您给了我们家庭作业!!!!!您能解释一下代码对我们ASP.NET开发人员的作用吗。@sikender.no这是一个真正的问题(相关)第一个google serp“ASP.NET curl”=>如果响应有xml文件,如何处理this@GodIsLive,更正了代码,并在答案中查看我的编辑。