Last active
January 29, 2021 23:05
-
-
Save dkeza/d5f9b5373c4282fae2b8037ec311fd86 to your computer and use it in GitHub Desktop.
golang Content-Type: multipart/form-data; boundary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"io/ioutil" | |
"net/http" | |
"strings" | |
) | |
func main() { | |
http.HandleFunc("/", root) | |
http.HandleFunc("/collect_bookings", multipart) | |
http.ListenAndServe(":8090", nil) | |
} | |
func root(w http.ResponseWriter, r *http.Request) { | |
io.WriteString(w, "Landed") | |
} | |
func multipart(w http.ResponseWriter, r *http.Request) { | |
if r.Method != "POST" { | |
io.WriteString(w, "Only POST is supported!") | |
return | |
} | |
b, err := ioutil.ReadAll(r.Body) | |
if err != nil { | |
fmt.Println(err) | |
} | |
// Calling ParseMultipartForm, with maxMemory = 0. Tried also with 32, 10000 etc. but without success. | |
r.ParseMultipartForm(0) | |
v := r.FormValue("HotelCode") | |
// v is empty | |
fmt.Println("HotelCode", v) | |
s := string(b) | |
fmt.Println(s) | |
xml := "" | |
if strings.Contains(s, "1111") { | |
xml = `<?xml version="1.0"?><Status Code="1111" />` | |
} else { | |
xml = `<?xml version="1.0"?><Status Code="2222" />` | |
} | |
w.Header().Set("Content-Type", "text/xml; charset=utf-8") | |
io.WriteString(w, xml) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ty dude, you solved my problem :)