1

我正在尝试将带有输入字段的 http 表单转换为可以放入微控制器代码中的基本文件。我缺少一些基本的东西,因为服务器不接受该值。这是我尝试将其转换为输入字段中的名称值对后的代码

<html>
<body>
    <form action="website"
        enctype="multipart/form-data" method="post">
        <utcdatatime="2013-06-16T23:20:40"&leftsource="1"&rightsource="1"&automatictransfer="1"&eventstatus="1"&preferred="1">
    </form>
</body>
</html>

这是输入字段版本:

<html>
<body>
    <form action="website"
        enctype="multipart/form-data" method="post">

                    <input type="text" name="utcdatatime" size="20" value="2013-06-16T23:20:40" />

                    <input type="text" name="leftsource" size="2" value="1" />

                    <input type="text" name="rightsource" size="2" value="4" />

                    <input type="text" name="automatictransfer" size="2" value="4" />

                    <input type="text" name="eventstatus" size="2" value="2" />

                    <input type="text" name="preferred" size="2" value="1" />
                    <input type="submit" value="Send" />
    </form>
</body>
</html>

我能够得到一个基本的帖子,但是这个代码对于一个 arduino 构建然后发送来说非常繁重,我也无法让第二行的/在 Arduino 中工作,但我想我会想到的出去

POST /post_url.php HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Content-Type: multipart/form-data; boundary=---------------------------7dd35a2aab1494
Accept-Encoding: gzip, deflate
Content-Length: 1018
DNT: 1
Host: website
Pragma: no-cache

-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="customerkey"

3432-1GH4-88RG-7B2A
-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="responsetype"

simple
-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="filetype"

sandc_microat
-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="gatewayid"

0011223355AA
-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="leftsource"

1
-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="rightsource"

4
-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="automatictransfer"

4
-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="eventstatus"

2
-----------------------------7dd35a2aab1494
Content-Disposition: form-data; name="automatictransfer"

1
-----------------------------7dd35a2aab1494--

========================== POST END=================================
4

1 回答 1

2

为什么你不能使用输入版本?您始终可以使用“隐藏”字段而不是“文本”字段:

<input type="hidden" name="rightsource" value="4" /> <!-- size attr not required -->

此外,除非您发布(上传)文件,否则我很确定您不需要 enctype,这会将 mime 数据插入帖子中,您可以将其删除。

这个 js fiddle 应该显示一个帖子示例以满足您的要求,这会在 arduino 系统上创建一个帖子请求并将其发送到 website/post_url.php:

http://jsfiddle.net/terrykernan/8z2VF/

于 2013-06-24T23:46:06.633 回答