我想上传一个zip文件到服务器使用http conn send!或后不纯港(或后纯港)。这是我的代码:
(define post
(lambda (url data header)
(call/input-url url
(lambda (url header)
(post-impure-port url data header))
port->string
header)))
;;; header
(define header
'("Content-Type: multipart/form-data"))
;;; some parameters
(define param `((resource_name . "google")
(version_name . "5.2")
(inner_version . "2.0")
(type . "GAME")
(sdk_id . "AndGoogle")
(for_platform . "Android")
(update_log . "test")))
(define data
(bytes-append
(string->bytes/utf-8
(alist->form-urlencoded param))
#"&file="
(file->bytes "file.zip")))
(post url data header)
但是输出是错误的,有人能告诉我怎么了吗?
谢谢您。
编辑
服务器响应
HTTP/1.1500内部服务器错误
服务器:apache coyote/1.1
x-application-context:应用程序:生产
内容长度:0
日期:2016年1月9日星期六01:53:29 GMT
连接:关闭
我想知道我是否应该添加一些这样的代码,尽管它不起作用:
(define CRLF "\r\n")
(define boundary "-------------------------RacketFormBoundaryf1nfLeDGcfc30oHf")
(define upload-file (file->bytes "AndGoogle.zip"))
(define data
(bytes-append
(->bytes (string-append
"--" boundary CRLF
"Content-Disposition: form-data; name=\"resource_name\"" CRLF
"AndGoogle" CRLF
"--" boundary CRLF
"Content-Disposition: form-data; name=\"version_name\"" CRLF
"5.2" CRLF
"--" boundary CRLF
"Content-Disposition: form-data; name=\"file\"; filename=\"AndGoogle.zip\"" CRLF
"Content-Type: application/zip" CRLF))
upload-file
(->bytes (string-append CRLF "--" boundary "--" CRLF))))
(define header
(list (string-append "Content-Type: multipart/form-data; boundary=" boundary)
(string-append "Content-Length: " (number->string (bytes-length data)))))
(post url data header)
最佳答案
我知道如何做到这一点后,得到帮助,从Racket用户组在谷歌,只需添加两个CRLF到分标题的形式。具体如下:
(define data
(bytes-append
(->bytes (string-append
"--" boundary CRLF
"Content-Disposition: form-data; name=\"resource_name\"" CRLF
CRLF
"AndGoogle" CRLF
"--" boundary CRLF
"Content-Disposition: form-data; name=\"version_name\"" CRLF
CRLF
"5.2" CRLF
"--" boundary CRLF
"Content-Disposition: form-data; name=\"file\"; filename=\"AndGoogle.zip\"" CRLF
"Content-Type: application/zip" CRLF
CRLF))
upload-file
(->bytes (string-append CRLF "--" boundary "--" CRLF))))