分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

newlisp HTTP Basic Authentication

发布时间:2023-09-06 01:47责任编辑:郭大石关键词:暂无标签
???????????????????????????
???????????????????????

HTTP Basic Authentication原来很easy,參考文档:http://zh.wikipedia.org/wiki/HTTP%E5%9F%BA%E6%9C%AC%E8%AE%A4%E8%AF%81

将username和password用:分隔,然后用base64编码。最后用HTTP GET方法请求页面

以下一小段代码用newLISP调用了Jenkins的Remote API:

dean@dean-beijing-home:~$ ./http.lsp hello<freeStyleBuild><action><cause><shortDescription>Started by upstream project "detail_summary_pipeline" build number 3</shortDescription><upstreamBuild>3</upstreamBuild><upstreamProject>detail_summary_pipeline</upstreamProject><upstreamUrl>job/detail_summary_pipeline/</upstreamUrl></cause></action><action></action><action><buildsByBranchName><refsremotesorigindevelop><buildNumber>8</buildNumber><marked><SHA1>8fe197b461d99b198551d9f50f3dc73cd5424c0b</SHA1><branch><SHA1>8fe197b461d99b198551d9f50f3dc73cd5424c0b</SHA1><name>refs/remotes/origin/develop</name></branch></marked><revision><SHA1>8fe197b461d99b198551d9f50f3dc73cd5424c0b</SHA1><branch><SHA1>8fe197b461d99b198551d9f50f3dc73cd5424c0b</SHA1><name>refs/remotes/origin/develop</name></branch></revision></refsremotesorigindevelop></buildsByBranchName><lastBuiltRevision><SHA1>8fe197b461d99b198551d9f50f3dc73cd5424c0b</SHA1><branch><SHA1>8fe197b461d99b198551d9f50f3dc73cd5424c0b</SHA1><name>refs/remotes/origin/develop</name></branch></lastBuiltRevision><remoteUrl>git@gitlab.bigdata.leshiren.com:datawarehouse/log_aggregation.git</remoteUrl><scmName></scmName></action><action></action><action></action><action></action><building>false</building><duration>105297</duration><estimatedDuration>95546</estimatedDuration><fullDisplayName>sum_user_query_day_cloud #8</fullDisplayName><id>2014-10-02_11-01-53</id><keepLog>false</keepLog><number>8</number><result>SUCCESS</result><timestamp>1412218913296</timestamp><url>http://10.100.86.22:8080/job/sum_user_query_day_cloud/8/</url><builtOn>slave25</builtOn><changeSet><kind>git</kind></changeSet></freeStyleBuild>

http.lsp源码例如以下:
#!/usr/bin/newlisp(println "hello")(set ‘user-pass "user:pwd")(set ‘auth (append "Authorization: Basic " (base64-enc user-pass) "\r\n"))(set ‘xml (get-url "http://your_jenkins/job/your_job/lastBuild/api/xml" 5000 auth))(println xml)(exit)

注意,get-url函数功能强大,这里的5000指的是超时时间,auth就是将编码后的username和password放在header里面发出去。


???????????????
???????????????????
???????????

newlisp HTTP Basic Authentication

原文地址:https://www.cnblogs.com/zhchoutai/p/8658632.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved