Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

golang http POST JSON content

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	httpposturl := "https://reqres.in/api/users"
	fmt.Println("HTTP JSON POST URL:", httpposturl)

	var jsonData = []byte(`{
		"name": "morpheus",
		"job": "leader"
	}`)
	request, error := http.NewRequest("POST", httpposturl, bytes.NewBuffer(jsonData))
	request.Header.Set("Content-Type", "application/json; charset=UTF-8")

	client := &http.Client{}
	response, error := client.Do(request)
	if error != nil {
		panic(error)
	}
	defer response.Body.Close()

	fmt.Println("response Status:", response.Status)
	fmt.Println("response Headers:", response.Header)
	body, _ := ioutil.ReadAll(response.Body)
	fmt.Println("response Body:", string(body))

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: req body express 
Javascript :: javascript function required arguments 
Javascript :: nextjs change port 
Javascript :: play audio with js 
Javascript :: remove current table row in jquery 
Javascript :: get select2 selected value jquery 
Javascript :: how to change color of font in js 
Javascript :: capitalize first letter after character javascript 
Javascript :: convert response to json javascript 
Javascript :: exit from fullscreen 
Javascript :: javascript get element tag 
Javascript :: javascript class constructor 
Javascript :: unload in jquery 
Javascript :: npm http angular 
Javascript :: js random in range 
Javascript :: regex urls 
Javascript :: node js to int 
Javascript :: mat checkbox change event in angular 7 
Javascript :: this keyword in javascript medium 
Javascript :: regex match line that does not contain string 
Javascript :: javascript array delete by index 
Javascript :: sessionstorage array 
Javascript :: is java and javascript the same 
Javascript :: sort array of objects by string property value 
Javascript :: jquery window trigger resize 
Javascript :: javascript conver time into 24 hour format 
Javascript :: safeareaview not working on android react native 
Javascript :: get elements by class is not working 
Javascript :: datepicker auto close 
Javascript :: select2 find option by value 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =