当前位置:网站首页>Unity sends a post request to the golang server for parsing and returning
Unity sends a post request to the golang server for parsing and returning
2022-07-29 07:13:00 【Handsome_ shuai_】
Unity send out Post Request to GoLang The server parses and returns
Use Unity send out Post Ask to GoLang Of Http The server ,Http After receiving the response, the server returns it to the client program
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 The server is turned on successfully !!!========")
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);
}
边栏推荐
- Flink实时仓库-DWD层(流量域)模板代码
- spark学习笔记(七)——sparkcore核心编程-RDD序列化/依赖关系/持久化/分区器/累加器/广播变量
- 模拟卷Leetcode【普通】222. 完全二叉树的节点个数
- pytest合集(7)— 参数化
- Student status management system based on C language design
- Vmware16 create virtual machine: win11 cannot be installed
- Pod基本介绍
- CVPR2022Oral专题系列(一):低光增强
- 【C语言刷LeetCode】1054. 距离相等的条形码(M)
- Win11vmware turns on the virtual machine and restarts on the blue screen and the solution that cannot be started
猜你喜欢

CVPR2022Oral专题系列(一):低光增强

Windows 上 php 7.4 连接 oracle 配置

Ansible中的变量及加密

WPF简单登录页面的完成案例

WPF嵌套布局案例

网上传说软件测试培训真的那么黑心吗?都是骗局?

VMware16创建虚拟机:无法创建新虚拟机,不具备执行此操作的权限

Nodejs安装教程

Is online legend software testing training really so black hearted? Are they all scams?

ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法
随机推荐
Flink real-time warehouse DWD layer (transaction domain - additional purchase dimension degradation processing) template code
npm install报错npm ERR Could not resolve dependency npm ERR peer
约瑟夫环问题
Teacher Wu Enda machine learning course notes 05 octave tutorial
[solution] error: lib/bridge_ generated. dart:837:9: Error: The parameter ‘ptr‘ of the method ‘FlutterRustB
gin 模版
330. 按要求补齐数组
Junda technology | applicable to "riyueyuan" brand ups wechat cloud monitoring card
微信小程序的反编译
[redis] redis development specifications and precautions
Thread - thread safety - thread optimization
Nodejs安装教程
Redis基础篇
gin 路由,参数,输出
上采样之反卷积操作
Cvpr2022oral special series (I): low light enhancement
gin 参数验证
gin 服务退出
Dbasql interview questions
【C语言刷LeetCode】2332. 坐上公交的最晚时间(M)