使用预先存在的PHP脚本将图像上传到服务器


Using a pre-existing PHP script to upload images to a server

我正在创建一个winform应用程序,需要将图像文件上传到中央图像服务器。在此之前,已经编写了一个预先存在的php脚本,允许通过门户网站将图像上传到服务器。我还被告知,我可以让我的程序访问这个PHP脚本并使用它的功能。

这怎么可能?

到目前为止,我已经尝试了以下代码行:

IPHostEntry ipHostInfo = System.Net.Dns.GetHostEntry("http://scriptlocation.html");
IPAddress ipAddress = ipHostInfo.AddressList[0];
using (TcpClient client = new TcpClient())
{
   client.Connect(ipAddress, 21);
   client.SendTimeout = 3000;
   var status = client.Connected;
   lblStatus.Text = status.ToString();
   Console.WriteLine(status);
}

但是当我运行这个时,我会得到以下错误;

没有已知的此类主机

我对这样的网络编程真的很陌生,有人能告诉我正确的方向吗?

如果我理解正确,您只是想将文件发送到http。

考虑使用WebClient:

using(var wc = new WebClient())
{
    wc.UploadData("http://scriptlocation.html", "POST", data);
}

其中data为文件字节数组;