简体   繁体   English

通过android中的http连接发送和接收字符串

[英]send and receive strings through http connection in android

I will try to keep my question simple.. using an arduino and an ethernet shield i have succesfully set up an http server. 我会尽量简化我的问题..使用arduino和以太网屏蔽,我已经成功设置了http服务器。 over a telnet interface i can send and receive strings between the server and my computer, and that's all i want. 通过telnet界面,我可以在服务器和计算机之间发送和接收字符串,这就是我想要的。 But i want to do it over an android application. 但是我想通过一个android应用程序来做。 i've done my searching and i've found that the simplest connection to an http server is by httpUrlConnection. 我已经完成搜索,并且发现与http服务器的最简单连接是通过httpUrlConnection。 But i have not managed to get it through. 但是我没有设法通过它。 Everywhere i searched there was the same exmple but i had problems with writeStream() and readStream().. just to be clear i do not want to use complicated methods like post, get, put etc etc, i just want to send and receive strings. 我到处搜索的地方都是相同的示例,但是我遇到了writeStream()和readStream()的问题。.为了清楚起见,我不想使用诸如post,get,put等复杂的方法,我只想发送和接收字符串。 thanks in advance, Loukas 在此先感谢,Loukas

edit:sorry but after some search i found out i can use http client and not http url connection because i have set up a server at the arduino. 编辑:对不起,但是经过一番搜索,我发现我可以使用http客户端而不是http url连接,因为我已经在arduino上设置了服务器。 my question now is how can i simulate telnet through http, i have found only examples tha use sockets, i want to use httpclient and just send and receive stings like telnet, thanks and i am really sorry i cannot be more clear.. 我现在的问题是如何通过http模拟telnet,我只发现了使用套接字的示例,我想使用httpclient并仅发送和接收telnet之类的消息,谢谢,非常抱歉,我无法更清楚地知道。

Indeed I can't see the "writeStream" or "readStream" routines in your app. 确实,我在您的应用程序中看不到“ writeStream”或“ readStream”例程。 If you made a copy-paste from somewhere, you might want to look at the definitions for those functions... 如果您从某处复制粘贴,则可能需要查看这些函数的定义...

I googled for an example that looked similar to yours and found this, not sure if it'll help: 我在Google上搜索了一个看起来与您相似的示例,但发现了这一点,不确定是否会有所帮助:

http://pastebin.com/gE650RrS http://pastebin.com/gE650RrS

In a nutshell: you need to create those methods. 简而言之:您需要创建那些方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM