当前位置:网站首页>Unity发送Post请求给GoLang服务端解析并返回
Unity发送Post请求给GoLang服务端解析并返回
2022-07-29 06:27:00 【帅_shuai_】
Unity发送Post请求给GoLang服务端解析并返回
使用Unity发送Post请求到GoLang的Http服务器,Http服务器接收响应后返回给客户端程序
GoLang
type ServerHttp struct {
HttpServerName string
}
func NewServerHttp(serverName string) *ServerHttp {
s := &ServerHttp{
HttpServerName: serverName,
}
return s
}
func (s *ServerHttp) Serve() {
go func() {
http.HandleFunc("/Account", s.accountHandle)
serverHttp := &http.Server{
Addr: global.HttpServerUrl,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
err := serverHttp.ListenAndServe()
if err != nil {
logger.PopError(err)
return
}
logger.PopDebug("========Http服务器开启成功!!!========")
select {
}
}()
}
func (s *ServerHttp) accountHandle(resWriter http.ResponseWriter, req *http.Request) {
err := req.ParseForm()
if err != nil {
fmt.Println(err)
return
}
val := req.Form.Get("id")
fmt.Println(val)
_, err = resWriter.Write([]byte(val))
if err != nil {
fmt.Println(err)
return
}
}
Unity
IEnumerator Start()
{
WWWForm wwwForm = new WWWForm();
wwwForm.AddField("id",666);
UnityWebRequest webRequest = UnityWebRequest.Post("http://127.0.0.1:9301/Account", wwwForm);
yield return webRequest.SendWebRequest();
if (webRequest.error!=null)
{
Debug.LogWarning(webRequest.error);
}
Debug.Log(webRequest.downloadHandler.text);
}
边栏推荐
猜你喜欢

Ali gave several SQL messages and asked how many tree search operations need to be performed?

Student achievement ranking system based on C language design

vscode通过remotessh结合xdebug远程调试php解决方案

Leetcode-592: fraction addition and subtraction

二次元卡通渲染——进阶技巧

VMware16安装虚拟机遇到的问题

Cvpr2022oral special series (I): low light enhancement

聊天机器人有何用处?有何类型?看完这些就明白了!

Unity免费元素特效推荐

【charles日常问题】开启charles,使用不了钉钉
随机推荐
mysql查询区分大小写
ECCV 2022丨轻量级模型架ParC-Net 力压苹果MobileViT代码和论文下载
LeetCode 879. 盈利计划
Teacher Wu Enda's machine learning course notes 00 are written in the front
MySQL: what happens in the bufferpool when you crud? Ten pictures can make it clear
Junda technology | applicable to "riyueyuan" brand ups wechat cloud monitoring card
Is online legend software testing training really so black hearted? Are they all scams?
gin 参数验证
resize2fs: 超级块中的幻数有错(Bad magic number in super-block )
IO stream - file - properties
Teacher Wu Enda's machine learning course notes 02 univariate linear regression
MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of
Flink real time warehouse DWD layer (traffic domain) template code
gin 模版
2D cartoon rendering - advanced skills
Windows 上 php 7.4 连接 oracle 配置
Teacher Wu Enda machine learning course notes 05 octave tutorial
MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of
竣达技术 | 适用于”日月元”品牌UPS微信云监控卡
Hj37 statistics of the total number of rabbits per month Fibonacci series