zoukankan      html  css  js  c++  java
  • Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fromHere.com' is therefore not allowed access.

    Failed to load http://wantTOgo.com/get_sts_token/:
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    Origin 'http://fromHere.com' is therefore not allowed access.

    package main

    import (
    "./myKey"
    "fmt"
    "os"

    "github.com/aliyun/aliyun-sts-go-sdk/sts"
    "github.com/labstack/echo"
    "github.com/labstack/echo/middleware"
    "net/http"
    )

    func handleError(err error) {
    fmt.Println(err)
    os.Exit(-1)
    }

    const (
    accessKeyID = myKey.AccessKeyID
    accessKeySecret = myKey.AccessKeySecret
    roleArn = myKey.RoleArn
    sessionName = myKey.SessionName
    )

    type ExceptionResp struct {
    Status string
    Message string
    }

    func main() {
    e := echo.New()
    e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
    // AllowOrigins: []string{"https://labstack.com", "https://labstack.net"},
    AllowOrigins: []string{"*"},
    // AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
    AllowHeaders: []string{"*"},
    }))
    e.GET("/aliSTS/:uid", func(c echo.Context) error {
    uid := c.Param("uid")
    fmt.Println("LOG ", uid)
    stsClient := sts.NewClient(accessKeyID, accessKeySecret, roleArn, sessionName)
    resp, err := stsClient.AssumeRole(3600)
    if err != nil {
    handleError(err)
    r := &ExceptionResp{
    Status: "-1",
    Message: "what?",
    }
    return c.JSON(http.StatusOK, r)
    }
    r := resp.Credentials
    return c.JSON(http.StatusOK, r)
    })
    e.Logger.Fatal(e.Start(":1324"))
    }


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>
    </body>
    </html>
    <script>
    const ourSTSurl = 'http://blackhole.com:1324/aliSTS/33333'
    const xhr = new XMLHttpRequest()
    const verb = 'GET'
    xhr.open(verb,ourSTSurl)
    xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr.send()
    console.log(xhr)
    </script>
    
    





  • 相关阅读:
    Netty ByteBuf(图解之 2)| 秒懂
    【转】 RGB各种格式
    缺少动态库报错
    bug:进程可调用函数而子线程调用报错
    【转】 pthread设置线程的调度策略和优先级
    【转】 C++析构函数的作用和用法
    【转】 g++编译时对'xxxx'未定义的引用问题(undefined reference to)
    【转】 C语言文件操作详解
    【转】 H.264编码原理以及I帧B帧P帧
    【转】 strrchr()函数---C语言
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9562866.html
Copyright © 2011-2022 走看看