亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

按屬性讀取 XML

按屬性讀取 XML

陪伴而非守候 2022-09-12 16:31:57
嘗試使用 Golang 連接到 MS 共享點,如這里所述,所以我寫了下面返回 XML 文本的內容:package mainimport (    "bytes"    "encoding/xml"    "fmt"    "io/ioutil"    "log"    "net/http"    "strings")func main() {    const myurl = "https://login.microsoftonline.com/extSTS.srf"    const username = "[email protected]"    const password = "mypassword"    const endpoint = "https://mydomain.sharepoint.com/"    const xmlbody = `    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"    xmlns:a="http://www.w3.org/2005/08/addressing"    xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header>  <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>  <a:ReplyTo>    <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>  </a:ReplyTo>  <a:To s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To>  <o:Security s:mustUnderstand="1"     xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">    <o:UsernameToken>      <o:Username>` + username + `</o:Username>      <o:Password>` + password + `</o:Password>    </o:UsernameToken>  </o:Security></s:Header><s:Body>  <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">    <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">      <a:EndpointReference>        <a:Address>` + endpoint + `</a:Address>      </a:EndpointReference>    </wsp:AppliesTo>    <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>    <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>    <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>  </t:RequestSecurityToken></s:Body></s:Envelope>`    resp, err := http.Post(myurl, "text/xml", strings.NewReader(xmlbody))    if err != nil {        log.Fatal(err)    }    defer resp.Body.Close()    body, _ := ioutil.ReadAll(resp.Body)    fmt.Println("response Body:", string(body))}
查看完整描述

1 回答

?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

跟:

    Attrs   []xml.Attr `xml:"-"`

您忽略了所有屬性。您應該能夠執行以下操作:

   ID string `xml:"Id,attr"

相反,請檢查您要查找的ID。

您收到該錯誤,因為它是一個數組。不能將數組與字符串值進行比較。n.Attrs


查看完整回答
反對 回復 2022-09-12
  • 1 回答
  • 0 關注
  • 81 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號