本文整理汇总了Golang中github.com/jmcvetta/napping.Session.Post方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Post方法的具体用法?Golang Session.Post怎么用?Golang Session.Post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jmcvetta/napping.Session
的用法示例。
在下文中一共展示了Session.Post方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// Start Session
s := napping.Session{}
url := BASE_URL + "get/sample"
fmt.Println("URL:>", url)
fmt.Println("--------------------------------------------------------------------------------")
println("")
fooParams := napping.Params{"md5": SAMPLE, "apikey": API_KEY}
p := fooParams
res := ResponseUserAgent{}
resp, err := s.Post(url, &p, &res, nil)
if err != nil {
fmt.Println("Error in request")
}
//
// Process response
//
println("")
fmt.Println("response Status:", resp.Status())
fmt.Println("--------------------------------------------------------------------------------")
fmt.Println("Header")
fmt.Println(resp.HttpResponse().Header)
fmt.Println("--------------------------------------------------------------------------------")
fmt.Println("RawText")
fmt.Println(resp.RawText())
println("")
}
示例2: instruct
func instruct(a *Coaction) *NodeResp {
fmt.Println("Instructed " + a.Instruction + " for id " + strconv.Itoa(a.Id))
v, _ := streamlut[a.Id]
url := "http://127.0.0.1:" + strconv.Itoa(v.Rconf.Lport) + "/player/" + a.Instruction
fmt.Println("Instructed as " + url)
var answer NodeResp
e := struct {
Message string
Errors []struct {
Resource string
Field string
Code string
}
}{}
s := napping.Session{}
var forwarder *Forwarder = nil
if (a.Instruction == "alterviewpoint") || (a.Instruction == "mouseclick") {
forwarder = &Forwarder{a.Cmdargs}
}
resp, err := s.Post(url, forwarder, &answer, &e)
if err != nil {
return &NodeResp{false, err.Error()}
}
if resp.Status() != 200 {
return &NodeResp{false, strconv.Itoa(resp.Status()) + "..." + e.Message}
}
return &answer
}
示例3: callPeer
func callPeer(watchmetadata *Watchmedata, destination *utilities.OPData, queue *lane.Queue, verb string, wg *sync.WaitGroup) {
defer wg.Done()
target := "http://" + destination.Ovip + ":" + strconv.Itoa(destination.Announceport) + "/ovp"
url := target + "/" + verb
fmt.Println("Instructed as " + url)
e := struct {
Message string
Errors []struct {
Resource string
Field string
Code string
}
}{}
var j map[string]interface{}
s := napping.Session{}
resp, err := s.Post(url, watchmetadata, &j, &e)
if err != nil {
log.Printf("failed to " + verb + " on " + target + " because " + err.Error())
return
}
if resp.Status() != 200 {
log.Printf("failed to " + verb + " on " + target + " because " + strconv.Itoa(resp.Status()) + "..." + e.Message)
return
}
if verb == "withdraw" || verb == "update" {
source := watchmetadata.OPConfig
if j["Status"].(bool) {
queue.Enqueue(destination)
} else {
mesg := fmt.Sprintf("Not "+verb+" %+v from %+v", source, destination)
panic(mesg)
}
}
queue.Enqueue(*destination)
}
示例4: SendRequest
func SendRequest(u string, method int, sess *napping.Session, pload interface{}, res interface{}) (error, *napping.Response) {
//
// Send request to server
//
e := httperr{}
var (
err error
resp *napping.Response
)
sess.Log = debug
switch method {
case GET:
resp, err = sess.Get(u, nil, &res, &e)
case POST:
resp, err = sess.Post(u, &pload, &res, &e)
case PUT:
resp, err = sess.Put(u, &pload, &res, &e)
case PATCH:
resp, err = sess.Patch(u, &pload, &res, &e)
case DELETE:
resp, err = sess.Delete(u, &res, &e)
}
if err != nil {
return err, resp
}
if resp.Status() == 401 {
return errors.New("unauthorised - check your username and passwd"), resp
}
if resp.Status() >= 300 {
return errors.New(e.Message), resp
} else {
// all is good in the world
return nil, resp
}
}
示例5: TestAllRight
func (s *TestSuite) TestAllRight(c *C) {
BASE_URL := "http://127.0.0.1:9999"
cur_dir, err := os.Getwd()
if err != nil {
c.Error(err)
}
test_file := path.Join(cur_dir, "temp/a.png")
finite_url := BASE_URL + test_file
log.Println(finite_url)
// ============ authenticate ==================
session := napping.Session{
Userinfo: url.UserPassword("admin", "admin"),
}
// ==========================================
for i := 1; i <= 10; i++ {
log.Println("Working ", i)
result := IdioticJSON{}
payload := StandartJSON{}
payload["Artist"] = uuid.NewV4().String()
payload["Author"] = uuid.NewV4().String()
payload["Comment"] = uuid.NewV4().String()
payload["Copyright"] = uuid.NewV4().String()
// wait for server to be up ..
_, err = session.Post(finite_url, &payload, &result, nil)
for err != nil {
_, err := session.Post(finite_url, &payload, &result, nil)
if err == nil {
break
}
}
c.Assert(result.Items[0]["Artist"], Equals, payload["Artist"])
c.Assert(result.Items[0]["Author"], Equals, payload["Author"])
c.Assert(result.Items[0]["Comment"], Equals, payload["Comment"])
c.Assert(result.Items[0]["Copyright"], Equals, payload["Copyright"])
}
}
示例6: main
func main() {
//
// Prompt user for Github username/password
//
var username string
fmt.Printf("Github username: ")
_, err := fmt.Scanf("%s", &username)
if err != nil {
log.Fatal(err)
}
passwd, err := gopass.GetPass("Github password: ")
if err != nil {
log.Fatal(err)
}
//
// Compose request
//
// http://developer.github.com/v3/oauth/#create-a-new-authorization
//
payload := struct {
Scopes []string `json:"scopes"`
Note string `json:"note"`
}{
Scopes: []string{"public_repo"},
Note: "testing Go napping" + time.Now().String(),
}
//
// Struct to hold response data
//
res := struct {
Id int
Url string
Scopes []string
Token string
App map[string]string
Note string
NoteUrl string `json:"note_url"`
UpdatedAt string `json:"updated_at"`
CreatedAt string `json:"created_at"`
}{}
//
// Struct to hold error response
//
e := struct {
Message string
Errors []struct {
Resource string
Field string
Code string
}
}{}
//
// Setup HTTP Basic auth for this session (ONLY use this with SSL). Auth
// can also be configured on a per-request basis when using Send().
//
s := napping.Session{
Userinfo: url.UserPassword(username, passwd),
}
url := "https://api.github.com/authorizations"
//
// Send request to server
//
resp, err := s.Post(url, &payload, &res, &e)
if err != nil {
log.Fatal(err)
}
//
// Process response
//
println("")
if resp.Status() == 201 {
fmt.Printf("Github auth token: %s\n\n", res.Token)
} else {
fmt.Println("Bad response status from Github server")
fmt.Printf("\t Status: %v\n", resp.Status())
fmt.Printf("\t Message: %v\n", e.Message)
fmt.Printf("\t Errors: %v\n", e.Message)
pretty.Println(e.Errors)
}
println("")
}