根据接口服务端发送请求
来源:互联网 发布:淘宝特卖网站 编辑:程序博客网 时间:2024/06/05 18:49
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using LitJson;
public class Open : MonoBehaviour
{
public string UrlOpen = "http:/xxx";
public string UrlClose = "http://xxx";
void Start()
{
StartCoroutine(PostWay(UrlClose));
}
// Update is called once per frame
void Update()
{
}
IEnumerator PostWay(string Url)
{
Buiding b = new Buiding("用户名", "密码");
string data = JsonMapper.ToJson(b);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
string temp = System.Text.Encoding.UTF8.GetString(bytes);
print(temp);
using (UnityWebRequest webRequest = UnityWebRequest.Post(Url, temp))
{
UploadHandlerRaw handler = new UploadHandlerRaw(bytes);
handler.contentType = "application/json";
webRequest.uploadHandler = handler;
webRequest.SetRequestHeader("Accept", "application/json");
yield return webRequest.Send();
if (webRequest.isError)
{
Debug.Log(webRequest.error);
}
else
{
Debug.Log(webRequest.downloadHandler.text);
}
}
}
}
public class Buiding
{
public string userName { get; set; }
public string pwd { get; set; }
public Buiding(string a, string b)
{
userName = a;
pwd = b;
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using LitJson;
public class Open : MonoBehaviour
{
public string UrlOpen = "http:/xxx";
public string UrlClose = "http://xxx";
void Start()
{
StartCoroutine(PostWay(UrlClose));
}
// Update is called once per frame
void Update()
{
}
IEnumerator PostWay(string Url)
{
Buiding b = new Buiding("用户名", "密码");
string data = JsonMapper.ToJson(b);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
string temp = System.Text.Encoding.UTF8.GetString(bytes);
print(temp);
using (UnityWebRequest webRequest = UnityWebRequest.Post(Url, temp))
{
UploadHandlerRaw handler = new UploadHandlerRaw(bytes);
handler.contentType = "application/json";
webRequest.uploadHandler = handler;
webRequest.SetRequestHeader("Accept", "application/json");
yield return webRequest.Send();
if (webRequest.isError)
{
Debug.Log(webRequest.error);
}
else
{
Debug.Log(webRequest.downloadHandler.text);
}
}
}
}
public class Buiding
{
public string userName { get; set; }
public string pwd { get; set; }
public Buiding(string a, string b)
{
userName = a;
pwd = b;
}
}
0 0
- 根据接口服务端发送请求
- React JS 请求服务端接口
- 发送请求读取接口
- java 根据接口发送手机短信
- httprequst向服务端发送请求错误
- Winform 客户端向服务端发送http请求
- Hessian客户端向服务端发送请求头
- commons-httpclient 服务端模拟客户端发送请求
- 云片网--发送短信验证码服务端接口
- Flex客户端向服务端发送请求设置Timeout
- jquery 跨域发送请求 java做服务端
- HttpSendRequest向服务端发送数据,构造请求http头
- Android使用HttpURLConnection发送Post请求到服务端
- jdk,服务端模拟客户端发送请求工具类
- C#客户端发送Http请求与服务端通信
- ajax向服务端发送请求的简单使用
- 安卓N版本NuPlayer向服务端发送RTSP请求
- socket服务端,记录接受客户端发送的请求信息
- 理解CXF JaxWsDynamicClientFactory jaxb绑定时的错误
- Network Dictionary – cVLAN and sVLAN
- opencv的基本数据结构
- s5pv210——按键
- 算法导论程序11--堆排序算法(Python)
- 根据接口服务端发送请求
- 1,List<VideoTotal> list; 根据VideoTotal的videoNum属性 把list 分组。2,把List<VideoTotal>list 根据VideoTotal属性去重
- Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
- 三目运算
- java:读取文件
- Butter Knife
- 全栈工程师之路-中级篇之小程序开发-第一章第一节注册小程序
- java的Object类的学习
- jq 与原生js 方法互相转换