Programlama ile uğraşırken yolunuz illaki birgün api‘lar ile çakışacaktır. Hele bunlardan REST ile içli dışlı olacaksanız aşağıdaki kod tam size göre.
Lazım olacak dursun buralarda bi yerlerde.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
apiUrl := "https://localhost:9090" resource := "/api/auth" data := url.Values{} data.Set("userName", "alierbey") data.Add("password", "123456") u, _ := url.ParseRequestURI(apiUrl) u.Path = resource urlStr := u.String() // "https://localhost:9090/api/auth" client := &http.Client{} r, _ := http.NewRequest("POST", urlStr, strings.NewReader(data.Encode())) r.Header.Add("Authorization", "") r.Header.Add("Content-Type", "application/json") r.Header.Add("Content-Type", "application/x-www-form-urlencoded") r.Header.Add("Content-Length", strconv.Itoa(len(data.Encode()))) resp, _ := client.Do(r) fmt.Println(resp.Status) |
Leave a Reply