当前位置:网站首页>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);
}
边栏推荐
- SSH password free login - two virtual machines establish password free channel two-way trust
- mysql可以定时导出表格吗?
- npm install报错npm ERR Could not resolve dependency npm ERR peer
- Flink实时仓库-DWD层(流量域)模板代码
- MySQL----多表查询
- Implementation of book borrowing management system based on C language
- Teacher Wu Enda's machine learning course notes 02 univariate linear regression
- WPF简单登录页面的完成案例
- Teacher Wu Enda's machine learning course notes 04 multiple linear regression
- 谷歌零碎笔记之JWT(草稿)
猜你喜欢

SSH password free login - two virtual machines establish password free channel two-way trust

做开发4年13K,想转行自动化测试,薪资还能涨吗···

Student achievement ranking system based on C language design

VMware16安装虚拟机遇到的问题

怎么会不喜欢呢,CICD中轻松发送邮件

上采样之反卷积操作

Federal learning backdoor attack summary (2019-2022)

Implementation of book borrowing management system based on C language

CVPR2021| 基于自监督学习的多视图立体匹配 (CVPR2021)

JS 鸡生蛋与蛋生鸡问题,Object与Function究竟谁出现的更早?Function算不算Function的实例?
随机推荐
Record - step on the pit - real-time data warehouse development - doris/pg/flink
基于C语言设计的学籍管理系统
gin 服务退出
Nodejs安装教程
[Charles' daily problems] when you open Charles, you can't use nails
Image noise and matrix inversion
【C语言刷LeetCode】1054. 距离相等的条形码(M)
WPF 界面布局必知基础
怎么会不喜欢呢,CICD中轻松发送邮件
Cvpr2022oral special series (I): low light enhancement
After three years of outsourcing, the salary of automatic testing after job hopping is twice that of the original. The secret is
Cesium反射
Win11vmware turns on the virtual machine and restarts on the blue screen and the solution that cannot be started
Vscode remote debugging PHP solution through remotessh and Xdebug
Cesium reflection
gin 中间件
After 4 years of development and 13K, if you want to change to automated testing, can your salary still rise···
最新百亿量化私募名单
Student status management system based on C language design
解决CSDN因版权不明而无法发布博客的问题