1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

net.http: add post_multipart_form function (#11511)

This commit is contained in:
Miccah
2021-09-15 23:34:07 -05:00
committed by GitHub
parent f295469fac
commit ead5e66afd
3 changed files with 73 additions and 2 deletions

View File

@@ -80,6 +80,22 @@ pub fn post_form(url string, data map[string]string) ?Response {
)
}
pub struct PostMultipartFormConfig {
form map[string]string
files map[string][]FileData
}
// post_multipart_form sends a POST HTTP request to the URL with multipart form data
pub fn post_multipart_form(url string, conf PostMultipartFormConfig) ?Response {
body, boundary := multipart_form_body(conf.form, conf.files)
return fetch(
method: .post
url: url
header: new_header(key: .content_type, value: 'multipart/form-data; boundary="$boundary"')
data: body
)
}
// put sends a PUT HTTP request to the URL with a string data
pub fn put(url string, data string) ?Response {
return fetch(