Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

node.js - Node Unirest Request.strictSSL(false) does not work for .attach()

I am able to authenticate and get some work item in my RTC localhost server https (self signed certificate), setting on unirest Request.strictSSL(false), but when I try to .attach() something, it does not works:

Code:

var cookies = unirest.jar();
async.waterfall([
    (callback) => {
        var req = unirest("POST", "https://localhost:9443/ccm/j_security_check")
            .headers({
                "Content-Type": "application/x-www-form-urlencoded",
            })
            .strictSSL(false)
            .jar(cookies)
            .send("j_username=samuel")
            .send("j_password=samuel")
            .end(function(res) {
                if (res.error) throw new Error(res.error);
                console.log('logged');
                callback();
            });
    },
    (callback) => {
        var req = unirest("GET", "https://localhost:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/2")
            .headers({
                Accept: "application/json",
            })
            .jar(cookies)
            .strictSSL(false)
            .end(function(res) {
                if (res.error) throw new Error(res.error);
                console.log(res.raw_body);
                callback();
            });
    },
    (callback) => {
        var req = unirest(
                "POST",
                "https://localhost:9443/ccm/service/com.ibm.team.workitem.service.internal.rest.IAttachmentRestService?projectId=_Jv0jwFXOEeuKc9Bmrq6cOA&multiple=true"
            )
            .strictSSL(false)
            .jar(cookies)
            .attach(
                "file",
                "https://url_to_img"
            )
            .end(function(res) {
                if (res.error) {
                    console.error(res.error);
                } else {
                    console.log('attach worked');
                }
            });
    }
])

Output:

logged
{...workitem}
{ Error: self signed certificate
    at TLSSocket.onConnectSecure (_tls_wrap.js:1058:34)
    at TLSSocket.emit (events.js:198:13)
    at TLSSocket._finishInit (_tls_wrap.js:636:8) code: 'DEPTH_ZERO_SELF_SIGNED_CERT' }

I was able to upload a file using Postman, setting the config "SSL certificate verification" to off. So what I'm missing on unirest?

question from:https://stackoverflow.com/questions/65832455/node-unirest-request-strictsslfalse-does-not-work-for-attach

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...