upload_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package http
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "net/http"
  6. "strings"
  7. "testing"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func Test(t *testing.T) {
  11. convey.Convey("upload", t, func() {
  12. url := "http://127.0.0.1:7331/x/admin/apm/ut/upload"
  13. payload := strings.NewReader("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; " +
  14. "name=\"html_file\"\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; " +
  15. "name=\"mid\"\r\n\r\n6\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; " +
  16. "name=\"username\"\r\n\r\nchengxing\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: " +
  17. "form-data; name=\"report_file\"\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--")
  18. req, _ := http.NewRequest("POST", url, payload)
  19. req.Header.Add("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
  20. req.Header.Add("Cookie", "_AJSESSIONID=cf81d40c0e9d960a0ce89ceeb05c5670; username=chengxing; "+
  21. "sven-apm=4104f6b8cb1d967a0dd45d6934638ba2bfc86cd239bf7bab095b8a1cc3f85b65")
  22. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  23. req.Header.Add("Cache-Control", "no-cache")
  24. req.Header.Add("Postman-Token", "69b1317b-0b01-43a0-a85d-c899f64ae34e")
  25. res, _ := http.DefaultClient.Do(req)
  26. body, _ := ioutil.ReadAll(res.Body)
  27. defer res.Body.Close()
  28. fmt.Println(string(body))
  29. })
  30. }