/*
* Get:参数在链接里,?后为参数
* Post:参数在表单;空间大
*/
public class WWWTest : MonoBehaviour
{
//定义一个Get线程,传入参数是URL(统一资源定位器)
public IEnumerator SendGet(string url)
{
WWW www = new WWW(url);
yield return www;
//判断下载是否有误
if (string.IsNullOrEmpty(www.error))
{
Debug.Log("下载完成");
}
}
//定义一个post,post参数在表单里,不在url;
public IEnumerator SendPost(string url, WWWForm form)
{
WWW www = new WWW(url, form);
yield return www;
}
// Start is called before the first frame update
void Start()
{
string url = "https://www.bilibili.com/video/BV1Q54y1U74b?p=17";
StartCoroutine(SendGet(url));
//post线程
string url2 = "https://www.bilibili.com/video/BV1Q54y1U74b";
WWWForm form = new WWWForm();
form.AddField("p", 17);
StartCoroutine(url2, form);
}
Get和Post的实现
最新推荐文章于 2022-08-07 21:11:08 发布
本文档展示了如何在Unity中通过C#实现GET和POST HTTP请求。`SendGet`方法用于GET请求,接收URL作为参数,而`SendPost`方法处理POST请求,使用`WWWForm`来传递表单数据。在示例中,两个方法都在`Start`函数中被调用,分别用于获取和提交B站视频页面的数据。
摘要由CSDN通过智能技术生成