newlisp HTTP Basic Authentication,newlisp

來源:互聯網
上載者:User

newlisp HTTP Basic Authentication,newlisp

HTTP Basic Authentication原來非常簡單,參考文檔:http://zh.wikipedia.org/wiki/HTTP%E5%9F%BA%E6%9C%AC%E8%AE%A4%E8%AF%81

將使用者名稱和密碼用:分隔,然後用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就是將編碼後的使用者名稱和密碼放在header裡面發出去。



什是http basic authentication

參考資料:smalltalllong.iteye.com/blog/912046
裡面說的挺清楚的
 
java basic認證

如果對JAVA感興趣的朋友可以看看瘋狂JAVA的視頻和書籍 可以來這裡學習 認證的話基本沒什麼用
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.