您是否考虑过 Web 服务?几乎任何可以发送 Http 请求的语言都可以使用它们。如果您可以控制客户端应用程序,那么 Web 服务绝对是正确的途径。
http://sarangasl.blogspot.com/2010/09/create-simple-web-service-in-visual.html
编辑:
您是否考虑过使用 http 响应代码进行简单的 http 字节上传。即 Http Ok,Http 失败。您可以将状态代码自定义为适合您项目的任何内容。
编辑2:
也许只有 http 状态代码作为响应的 RPC 风格的方法可能是合适的。检查此问题以获取提示。使用 C# 调用 json
基本上,您只是将一些字符串发送到 url,然后接收状态码。那是很小的。
编辑3:
这是我使用 Reflector 从一些旧代码中提取的内容。这只是该程序的一般要点。显然,第一个请求应该有一个 using 语句。
public void SMS(Uri address, string data)
{
// Perhaps string data is JSON, or perhaps its something delimited who knows.
// Json seems to be the pretty lean.
try
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(address);
request.Method = "POST";
// If we don't setup proxy information then IE has to resolve its current settings
// and adds 500+ms to the request time.
request.Proxy = new WebProxy();
request.Proxy.IsBypassed(address);
request.ContentType = "application/json;charset=utf-8";
// If your only sending two bits of data why not add custom headers?
// If you only send headers, no need for the StreamWriter.
// request.Headers.Add("SMS-Sender","234234223");
// request.Headers.Add("SMS-Body","Hey mom I'm keen for dinner tonight :D");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.WriteLine(data);
writer.Close();
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
// Either read the stream or get the status code and description.
// Perhaps you won't even bother reading the response stream or the code
// and assume success if no HTTP error status causes an exception.
}
}
}
catch (WebException exception)
{
if (exception.Status == WebExceptionStatus.ProtocolError)
{
// Something,perhaps a HTTP error is used for a failed SMS?
}
}
}
请记住仅使用 Http 状态代码和描述进行响应。并确保请求的代理设置为绕过请求 URL,以节省解析 IE 代理的时间。