我的帖子请求有标题,但我不知道如何以二进制和压缩方式发送数据。这是我的curl命令:
curl 'http://192.168.1.90:333/sendMessage.srv'
-H 'Origin: http://192.168.1.90:333'
-H 'Accept-Encocding: gzip, deflate'
-H 'Accept-Language: en-US,en;q=0.9'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
-H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryycti6tczDNAO3xqF'
-H 'Accept: */*'
-H 'Referer: http://192.168.1.90:333/'
-H 'X-Requested-With: XMLHttpRequest'
-H 'Connection: keep-alive'
--data-binary PAYLOAD --compressed
这是我尝试发送的有效负载
------WebKitFormBoundaryycti6tczDNAO3xqF
Content-Disposition: form-data; name="hashid"
+12223334444
------WebKitFormBoundaryycti6tczDNAO3xqF
Content-Disposition: form-data; name="reqUID"
wxyz
------WebKitFormBoundaryycti6tczDNAO3xqF
Content-Disposition: form-data; name="recipients"
------WebKitFormBoundaryycti6tczDNAO3xqF
Content-Disposition: form-data; name="file-name"
------WebKitFormBoundaryycti6tczDNAO3xqF
Content-Disposition: form-data; name="text"
message
------WebKitFormBoundaryycti6tczDNAO3xqF--
或在1行上
$'------WebKitFormBoundaryk7s3ZvI9evAhMsEL\r\nContent-Disposition: form-data; name="hashid"\r\n\r\n+12223334444\r\n------WebKitFormBoundaryk7s3ZvI9evAhMsEL\r\nContent-Disposition: form-data; name="reqUID"\r\n\r\nly9a\r\n------WebKitFormBoundaryk7s3ZvI9evAhMsEL\r\nContent-Disposition: form-data; name="recipients"\r\n\r\n\r\n------WebKitFormBoundaryk7s3ZvI9evAhMsEL\r\nContent-Disposition: form-data; name="file-name"\r\n\r\n\r\n------WebKitFormBoundaryk7s3ZvI9evAhMsEL\r\nContent-Disposition: form-data; name="text"\r\n\r\nmessage\r\n------WebKitFormBoundaryk7s3ZvI9vAhMsEL--\r\n'
这是我的代码:
body := strings.NewReader(`$------WebKitFormBoundaryU8vOdhYkInm8YBuZ\r\nContent-Disposition: form-data; name="hashid"\r\n\r\n+12223334444\r\n------WebKitFormBoundaryU8vOdhYkInm8YBuZ\r\nContent-Disposition: form-data; name="reqUID"\r\n\r\nvvpr\r\n------WebKitFormBoundaryU8vOdhYkInm8YBuZ\r\nContent-Disposition: form-data; name="recipients"\r\n\r\n\r\n------WebKitFormBoundaryU8vOdhYkInm8YBuZ\r\nContent-Disposition: form-data; name="file-name"\r\n\r\n\r\n------WebKitFormBoundaryU8vOdhYkInm8YBuZ\r\nContent-Disposition: form-data; name="text"\r\n\r\message\r\n------WebKitFormBoundaryU8vOdhYkInm8YBuZ--\r\n`)
req, err := http.NewRequest("POST", "http://192.168.1.90:333/sendMessage.srv", body)
if err != nil {
panic(err)
}
req.Header.Set("Origin", "http://192.168.1.90:333")
req.Header.Set("Accept-Encoding", "gzip, deflate")
req.Header.Set("Accept-Language", "en-US,en;q=0.9")
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36")
req.Header.Set("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryU8vOdhYkInm8YBuZ")
req.Header.Set("Accept", "*/*")
req.Header.Set("Referer", "http://192.168.1.90:333/")
req.Header.Set("X-Requested-With", "XMLHttpRequest")
req.Header.Set("Connection", "keep-alive")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()