Hi, we are trying to capture response from a http request, which is giving response as a combination of json and non-json format, we want to capture the Token generated by the request using go language.
Below is the response format:
`$(“link.favicon”).attr(“href”, $.url(‘/web.shell.common/productBranding:/res/images/favicon.ico’));
`var pageView = new infaw.isp.SymphonyNextLoginPageView({
logo: "/web.shell.common/?fileName=loginPageLogo",
logo2: "",
namespaces : [{"id":"Native","label":"Native"}],
bgImages : [{"0":"/"},{"1":"/web.ldm./image2.jpg"},{"2":"/image3.jpg"}],
version : "Version 10.1",
modeURL : "web.isp/login",
year : "(c) Copyright 2023.",
isSAMLDomain:"false",
pageTitle: "Administrator",
Token: "XGD%2B-5EC11gFv0UUI7A*"
});`
I have written the below go function to capture the response from the request, It’s capturing the response white trying to capture the token, It’s failing with the below error.
`
package main
import (
"encoding/json"
"fmt"
"net/http"
"io/ioutil"
"reflect"
)
type Asset struct {
Id string
Name string
}
func main() {
resp, err := http.Get(“httprequst”)
fmt.Println(resp)
if err != nil {
fmt.Println(err)
}
body, error := ioutil.ReadAll(resp.Body)
if error != nil {
fmt.Println(error)
}
// close response body
resp.Body.Close()
// print response body
fmt.Println(string(body))
var obj Asset
if err := json.NewDecoder(resp.Body).Decode(&obj); err != nil {
fmt.Println(resp.Body)
fmt.Println(err)
}
//stringData := json.parse(body)
mySimpleMap := make(map[string]interface{})
err1 := json.Unmarshal(byte(string(body)), &mySimpleMap)
if err1 != nil {
fmt.Println(“error while unmarshal”, err1)
} else {
fmt.Println(reflect.TypeOf(mySimpleMap[“Id”]))
fmt.Printf(“%f\n”, mySimpleMap[“Id”])
//fmt.Println(int(mySimpleMap[“Id”].(float64)))
}
myAsset := Asset{}
err = json.Unmarshal(byte(body), &myAsset)
if err != nil {
fmt.Println(“error while unmarshal”, err)
} else {
fmt.Printf(“%d”, myAsset.Id)
}`
Getting the below error after running the go code:
error while unmarshall invalid character ‘$’ looking for beginning of value