Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

RQM api interogation with Golang

 I try to inspect with Golang this RQM.


My code is:
package main

import (
"net/http"
"net/url"
"fmt"
"log"
"io/ioutil"
"crypto/tls"
"crypto/x509"
"strings"
"strconv"
)

func main() {
fmt.Println("Start program. ")
caCert, err := ioutil.ReadFile("rqm_certs.crt")

if err != nil {
log.Fatal(err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)


tr := &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs:      caCertPool,
InsecureSkipVerify: true,
},
}
client := &http.Client{
Transport: tr,
}
data := url.Values{}
data.Set("j_username", "test1")
data.Set("j_password", "test2")


req, err := http.NewRequest("POST", "https://test-server-jazz.example.com/rqm001/j_security_check", strings.NewReader(data.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Cookie", "JazzFormAuth=Form; Path=/rqm001; Secure")
req.Header.Set("OSLC-Core-Version", "3.0")
req.Header.Set("Accept", "application/xml")
req.Header.Set("Content-Length", strconv.Itoa(len(data.Encode())))
req.Header.Set("Configuration-Context", "_NQfiQI8PEeelKpQbl_90kA")
if err != nil {
log.Println(err)
}
resp, err := client.Do(req)
if err != nil {
log.Println(err)
}

f, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err)
}
resp.Body.Close()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(f))
fmt.Println(resp.Status)
}

But with inspect, this message appear:
net.jazz.ajax.ui.PlatformUI.createAndRunWorkbench("net.jazz.web.app.authrequired");

Does anyone know what the problem is here?
I tried other ways, but it gives me this error.


0 votes



One answer

Permanent link
You aren't authenticating properly - you should probably do a GET from the j_security_check before doing the POST. Or do a GET from a protected resource (e.g. https://server:port/qm/authenticated/identity) and you will be forced into authentication sequence - once the POST gets a 200, repeat the GET and it should work with a 200.

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,941

Question asked: Feb 17 '20, 1:18 p.m.

Question was seen: 1,067 times

Last updated: Feb 18 '20, 8:47 a.m.

Confirmation Cancel Confirm