新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)GoFrame教程:GoFrameHTTPClient-鏈?zhǔn)讲僮?/div>
鏈?zhǔn)讲僮?
?GOFrame?框架的客戶端支持便捷的鏈?zhǔn)讲僮?,常用方法如下?/p>

創(chuàng)新互聯(lián)于2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元日喀則做網(wǎng)站,已為上家服務(wù),為日喀則各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792
func (c *Client) Timeout(t time.Duration) *Client
func (c *Client) Cookie(m map[string]string) *Client
func (c *Client) Header(m map[string]string) *Client
func (c *Client) HeaderRaw(headers string) *Client
func (c *Client) ContentType(contentType string) *Client
func (c *Client) ContentJson() *Client
func (c *Client) ContentXml() *Client
func (c *Client) BasicAuth(user, pass string) *Client
func (c *Client) Retry(retryCount int, retryInterval time.Duration) *Client
func (c *Client) Prefix(prefix string) *Client
func (c *Client) Proxy(proxyURL string) *Client
func (c *Client) RedirectLimit(redirectLimit int) *Client
func (c *Client) Dump(dump ...bool) *Client
func (c *Client) Use(handlers ...HandlerFunc) *Client簡要說明:
- ?
Timeout?方法用于設(shè)置當(dāng)前請求超時時間。 - ?
Cookie?方法用于設(shè)置當(dāng)前請求的自定義?Cookie?信息。 - ?
Header*?方法用于設(shè)置當(dāng)前請求的自定義?Header?信息。 - ?
Content*?方法用于設(shè)置當(dāng)前請求的?Content-Type?信息,并且支持根據(jù)該信息自動檢查提交參數(shù)并自動編碼。 - ?
BasicAuth?方法用于設(shè)置?HTTP Basic Auth?校驗信息。 - ?
Retry?方法用于設(shè)置請求失敗時重連次數(shù)和重連間隔。 - ?
Proxy?方法用于設(shè)置?http?訪問代理。 - ?
RedirectLimit?方法用于限制重定向跳轉(zhuǎn)次數(shù)。
使用示例
示例1,請求超時控制
g.Client().Timeout(3*time.Second).GetContent(ctx, "http://user.svc/v1/user/info/1")g.Client().Timeout(10*time.Second).PostContent(ctx, "http://order.svc/v1/order/create", g.Map{
"uid" : 1,
"sku_id" : 10000,
"amount" : 19.99,
"create_time" : "2020-03-26 12:00:00",
})示例2,自定義Cookie
g.Client().SetCookie("sessionid", "MNV5432PIY76").GetContent(ctx, "http://user.svc/v1/user/info/1")示例3,自定義Header
g.Client().SetHeader("RequestId", "XVF654RT98UJNMN641V06Y").GetContent(ctx, "http://user.svc/v1/user/info/1")g.Client().HeaderRaw(`
Referer: https://GoFrame.org/
User-Agent: MyTesyClient
`).GetContent(ctx, "http://user.svc/v1/user/info")示例4,提交Json請求
g.Client().ContentJson().PostContent(ctx, "http://order.svc/v1/order/create", g.Map{
"uid" : 1,
"sku_id" : 10000,
"amount" : 19.99,
"create_time" : "2020-03-26 12:00:00",
})該請求將會將?Content-Type?設(shè)置為?application/json?,并且將提交參數(shù)自動編碼為?Json?:
{"uid":1,"sku_id":10000,"amount":19.99,"create_time":"2020-03-26 12:00:00"}示例5,提交Xml請求
g.Client().ContentXml().PostContent(ctx, "http://order.svc/v1/order/create", g.Map{
"uid" : 1,
"sku_id" : 10000,
"amount" : 19.99,
"create_time" : "2020-03-26 12:00:00",
})該請求將會將?Content-Type?設(shè)置為?application/xml?,并且將提交參數(shù)自動編碼為?Xml?:
19.99 2020-03-26 12:00:00 10000 1 當(dāng)前標(biāo)題:創(chuàng)新互聯(lián)GoFrame教程:GoFrameHTTPClient-鏈?zhǔn)讲僮?
本文鏈接:http://www.dlmjj.cn/article/dpeogps.html


咨詢
建站咨詢
