unity post 请求发送字符串
时间: 2023-11-24 12:05:31 浏览: 309
可以通过 UnityWebRequest.Post 方法来发送 POST 请求,其中需要传入请求的 URL 和要发送的字符串数据。例如:
```
using UnityEngine;
using UnityEngine.Networking;
public class MyScript : MonoBehaviour
{
void Start()
{
StartCoroutine(SendPostRequest());
}
IEnumerator SendPostRequest()
{
string url = "http://example.com/api";
string data = "name=John&age=30";
UnityWebRequest request = UnityWebRequest.Post(url, data);
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
Debug.Log("Post request sent successfully");
}
else
{
Debug.Log("Error sending post request: " + request.error);
}
}
}
```
阅读全文