我有一些其他職位,我一直在將數據發佈到UPnP打印機。基本上從頭開始創建一個控制點(這仍然是POC,我將在多種設備類型上實現,因此我試圖首先獲得基本的理解)。到目前爲止,我可以發現打印機,請求打印作業並找回數據吸收器URL以發佈要打印的內容。在這一點上我試圖用簡單的XHTML數據的POST,但請求似乎與下面的異常每次超時:UPnP POST到打印機數據接收器URI
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);
}
原始post數據,使我從印刷
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>
是流浪'「'收盤HTML標籤一個錯字後?你記住逃脫XHTML,如果它是一個SOAP消息話題裏面,如果沒有這些幫助,你能顯示整個POST(即HTTP頭+ SOAP消息以及xhtml)? – simonc
尾隨引用是一種類型,我將用我的請求數據更新問題。 – earthling
您沒有顯示請求正文。「SendToPrinter」中「content」的值是什麼?您是否將其格式化爲SOAP消息? – simonc