I am trying to get IPFS data via Infura, during parsing of json I am getting error in both golang and java, Please assist
func main() {
projectId := "1y....."
projectSecret := "1f9..."
client := &http.Client{}
req, _ := http.NewRequest("POST", "https://ipfs.infura.io:5001/api/v0/object/data?arg=QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/1", nil)
req.Header.Add("Authorization", "Basic "+basicAuth(projectId, projectSecret))
req.Header.Add("Content-type", "application/json")
response, err := client.Do(req)
if err != nil {
fmt.Printf("The HTTP request failed with error %s\n", err)
} else {
var nftData NFTTraitData
data, _ := ioutil.ReadAll(response.Body)
err := json.Unmarshal([]byte(data), &nftData)
if err != nil {
panic(err)
}
}
}
func basicAuth(projectId, projectSecret string) string {
auth := projectId + ":" + projectSecret
return base64.StdEncoding.EncodeToString([]byte(auth))
}
Error : panic: invalid character ‘\b’ looking for beginning of value
Java:
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(
"https://ipfs.infura.io:5001/api/v0/object/data?arg=QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/1")
.get().addHeader("Content-Type", "application/json")
.addHeader("Authorization",
"Basic MXl......")
.build();
Response response = client.newCall(request).execute();
String json = response.body().string();
System.out.println(response.headers());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
IpfsTokenResponse or = objectMapper.readValue(json, IpfsTokenResponse.class);
System.out.println("Request Succesful ");
Java error:
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 8)): only regular white space (\r, \n, \t) is allowed between tokens
at [Source: (String)"�{"image":"ipfs://QmPbxeGcXhYQQNgsC6a36dDyYUcHgMLnGKnF8pVFmGsvqi","attributes":[{"trait_type":"Mouth","value":"Grin"},{"trait_type":"Clothes","value":"Vietnam Jacket"},{"trait_type":"Background","value":"Orange"},{"trait_type":"Eyes","value":"Blue Beams"},{"trait_type":"Fur","value":"Robot"}]}
�"; line: 1, column: 2]