我还有其他一些帖子,我一直在将数据发布到UPnP打印机上。基本上从头开始创建一个控制点(这仍然是POC,我将在多种设备类型中实现,因此我首先尝试获得基本的理解)。到目前为止,我能够发现打印机,请求打印作业并返回数据接收URL以发布要打印的内容。此时我尝试使用简单的xhtml数据进行POST,但每次请求似乎超时,但出现以下异常:
The remote server returned an error: NotFound.
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)
如果我在浏览器中点击了网址,我会回来HTTP 405 Method Not Allowed
我想知道服务器是否由于数据错误而忽略了帖子,或者我在这些行中缺少标题或其他内容。
我已经浏览了upnp.org上有关Printer Basic服务的文档,以及SOAP 1.1 UPnP Profile,这两个文档都有很大的帮助。
有人有任何想法吗?
这是我的xhtml的副本:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML-Print 1.0//EN\" \"http://www.w3.org/MarkUp/DTD/xhtml-print10.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>test</title>
</head>
<body>
<div>hello world</div>
</body>
</html>
我正在使用C#创建并发送HttpWebRequest
。这是执行该操作的代码(我有几个版本,另一个使用WebClient
)
private void SendToPrinter(string printUri, string content)
{
var request = WebRequest.Create(new Uri(printUri)) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "text/xml; charset=\"utf-8\"";
request.ContentLength = content.Length;
request.Headers[SoapHeaderName] = CreateJobHeader; // this probably isn't necessary
request.BeginGetRequestStream(ar =>
{
var requestStream = request.EndGetRequestStream(ar);
using (var sw = new StreamWriter(requestStream))
{
sw.Write(content);
sw.Close();
}
request.BeginGetResponse(a =>
{
var response = request.EndGetResponse(a);
var responseStream = response.GetResponseStream();
using (var sr = new StreamReader(responseStream))
{
var results = sr.ReadToEnd();
}
}, null);
}, null);
}
来自fiddler的原始帖子数据
POST http://10.20.201.90/upnp/print/1d153438-1e90-1f0b-8b54-984be15df0fe HTTP/1.1
Content-Type: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:device:Printer:1#SendDocument"
Host: 10.20.201.90
Content-Length: 482
Expect: 100-continue
<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:SendDocument xmlns:u="urn:schemas-upnp-org:device:Printer:1"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>test</title></head><body><div>hello world</div></body></html></u:SendDocument></s:Body></s:Envelope>
答案 0 :(得分:0)
让我无法打印的一个问题是打印机设置为询问要打印的纸盘。这阻止了邮件的打印。这是最终的SOAP消息。我没有逃脱它。
<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head><title>test</title></head>
<body><div>hello world</div></body>
</html>
</s:Body>
</s:Envelope>