You are viewing an old version of this page. View the current version.
Compare with Current View Page History
Version 6 Next »
Json
g.Client().ContentJson().PostContent(ctx, "http://order.svc/v1/order", g.Map{ "uid" : 1, "sku_id" : 10000, "amount" : 19.99, "create_time" : "2020-03-26 12:00:00", })
该请求将会将Content-Type设置为application/json,并且将提交参数自动编码为Json:
Content-Type
application/json
{"uid":1,"sku_id":10000,"amount":19.99,"create_time":"2020-03-26 12:00:00"}
Xml
g.Client().ContentXml().PostContent(ctx, "http://order.svc/v1/order", g.Map{ "uid" : 1, "sku_id" : 10000, "amount" : 19.99, "create_time" : "2020-03-26 12:00:00", })
该请求将会将Content-Type设置为application/xml,并且将提交参数自动编码为Xml:
application/xml
<doc><amount>19.99</amount><create_time>2020-03-26 12:00:00</create_time><sku_id>10000</sku_id><uid>1</uid></doc>
ContentType
我们可以通过ContentType方法自定义客户端请求的ContentType。例如:
g.Client().ContentType("application/json").PostContent(ctx, "http://order.svc/v1/order", g.Map{ "uid" : 1, "sku_id" : 10000, "amount" : 19.99, "create_time" : "2020-03-26 12:00:00", })