使用Javascript将文本发送到端口

时间:2021-09-04 18:11:00

I recently got a new printer (specifically a HP Photosmart C6380 if that helps) that allows me to send text to port 9100 to print. Telnetting into it and typing text to print works fine, but I'm wondering if I could make a webpage using HTML and Javascript that can send text directly to it.

我最近有一台新打印机(特别是HP Photosmart C6380,如果有帮助),它允许我发送文本到端口9100进行打印。 Telnet进入它并输入文本进行打印工作正常,但我想知道我是否可以使用HTML和Javascript创建一个可以直接发送文本的网页。

I'm currently using the code from the article Cross Site Printing (pdf), but the downside is that when it prints out it shows the entire POST request and not just the text.

我目前正在使用文章Cross Site Printing(pdf)中的代码,但缺点是当它打印出来时它会显示整个POST请求而不仅仅是文本。

So my question for you is am I able to send just the content of the POST request or strip the unneeded characters using only HTML and Javascript?

所以我的问题是,我是否能够仅使用HTML和Javascript发送POST请求的内容或删除不需要的字符?

Note: The reason why it's limited to HTML and Javascript is because I'm hoping that I can use this on an iPhone or iPod Touch.

注意:它仅限于HTML和Javascript的原因是因为我希望我可以在iPhone或iPod Touch上使用它。

Edit: It appears that there's no way to get rid of the HTTP headers, so now my question is can I craft a custom POST request that will minimize on what is sent in the header? For example, can I not send the user agent since the printer doesn't care what the user agent is?

编辑:似乎没有办法摆脱HTTP标头,所以现在我的问题是我可以制作一个自定义POST请求,将最小化在标头中发送的内容?例如,我是否可以不发送用户代理,因为打印机不关心用户代理是什么?

2 个解决方案

#1


No, there's no way to get rid of the HTTP headers in client-side JavaScript. For that, you need to set up a server-side script which will then make the actual connection to the printer port.

不,没有办法摆脱客户端JavaScript中的HTTP头。为此,您需要设置一个服务器端脚本,然后与打印机端口建立实际连接。

Edit: The server-side script won't send a HTTP request to your printer: It should open a new socket and thus can fully controle what gets sent!

编辑:服务器端脚本不会向您的打印机发送HTTP请求:它应该打开一个新的套接字,因此可以完全控制发送的内容!

#2


You can HTTP-Request from within JS, so you always have an HTTP-Header, regardless of the port to which you are sending. So the answer is: no.

您可以在JS中使用HTTP-Request,因此无论您要发送哪个端口,都始终拥有HTTP-Header。所以答案是:不。

#1


No, there's no way to get rid of the HTTP headers in client-side JavaScript. For that, you need to set up a server-side script which will then make the actual connection to the printer port.

不,没有办法摆脱客户端JavaScript中的HTTP头。为此,您需要设置一个服务器端脚本,然后与打印机端口建立实际连接。

Edit: The server-side script won't send a HTTP request to your printer: It should open a new socket and thus can fully controle what gets sent!

编辑:服务器端脚本不会向您的打印机发送HTTP请求:它应该打开一个新的套接字,因此可以完全控制发送的内容!

#2


You can HTTP-Request from within JS, so you always have an HTTP-Header, regardless of the port to which you are sending. So the answer is: no.

您可以在JS中使用HTTP-Request,因此无论您要发送哪个端口,都始终拥有HTTP-Header。所以答案是:不。