0

我正在尝试让 arduino 登录到我创建的网站。
在网站上有一个基本表单,其中包含两个字段,一个用于密码,一个用于用户名,它还有一个标记为登录的提交按钮。

当我使用 chrome 登录时,我使用 fiddler2 来嗅探 http 数据包,并尝试使用该 http 帖子中的信息来重新创建我自己的登录帖子。

这是我用于登录的代码部分:

if (client.connect(server, 80)) {

 Serial.println("connected to server");

// Make a HTTP request:               
 client.println("POST/username=slwhore&passwd=1234qwer%21&op2=login&lang=english&force_session=1&return=B%3AaHR0cDovL3JlbW90bGV0LmNvbS8%3D&message=0&loginfrom=loginmodule&cbsecuritym3=cbm_56b7d5e7_00583e07_b0b6f81b4c86d117542f5cc7b7c3416e&Submit=Login HTTP/1.1");

client.println("Host:www.remotlet.com");

client.println("Content-Type: application/x-www-form-urlencoded");

client.println("Content-Length: 229");

client.println("Connection: close");

client.println();

然后我有另一段代码接收从我知道有效的主机返回的信息。当我运行此代码时,我能够连接到服务器,但我根本没有得到任何响应。任何帮助将不胜感激。

4

1 回答 1

2

Your HTTP request is completely wrong, it will never ever be accepted by any kind of server web.

1st line: the HTTP 1st line is METHOD URI VERSION. You didn't put a space between the method and the URI, also the POST data is not part of the URI as it is when using GET requests. I don't know what your server uses but usually sane logins don't use GET and don't pass the login inside the URI.

2nd line: you forgot a space

4th line: you set a content length but you don't send any content apparently.

General consideration: in HTTP the line terminator is \r\n, not just \n.

I suggest you do the request with the browser, intercept the traffic with wireshark and see how it's done.

于 2013-02-07T19:08:34.923 回答