因此,我已经为此苦苦挣扎了两天,但并没有取得很大的成功。
我得到的是由网页生成的 http POST,该网页被发送到我正在服务器上创建的 php 文件。所以基本上我正在尝试创建一个 php 侦听器脚本,当发生 http 帖子时,它将运行脚本将 xml 数据保存到 SimpleXMLElement 中,以便我可以编写一个 MYSQL 查询将数据导入我们的数据库。一旦我将数据放入 SimpleXMLElement,我就可以从那里接管,我遇到的问题是我无法让 listener.php 文件监听 HTTP POST 并将数据读入本地文件。
<?php
public void RunServer()
{
var prefix = "http://*:4333/";
HttpListener listener = new HttpListener();
listener.Prefixes.Add(prefix);
try
{
listener.Start();
}
catch (HttpListenerException hlex)
{
return;
}
while (listener.IsListening)
{
var context = listener.GetContext();
ProcessRequest(context);
}
listener.Close();
}
private void ProcessRequest(HttpListenerContext context)
{
// Get the data from the HTTP stream
var body = new StreamReader(context.Request.InputStream).ReadToEnd();
$data = body
byte[] b = Encoding.UTF8.GetBytes("ACK");
context.Response.StatusCode = 200;
context.Response.KeepAlive = false;
context.Response.ContentLength64 = b.Length;
var output = context.Response.OutputStream;
output.Write(b, 0, b.Length);
context.Response.Close();
}
?>
This code is the closest I've gotten to what I need and I get a 500 error when I try to access the page. I'm not going to lie I'm pretty new to php and am having issues understanding function definitions. (Also I did get this code from a StackOverflow ticket that was closed)
I'm currently using php5 and apache on my server for my web hosting. ] I have a php.info() file setup and can post it if need be.