UnityWebRequest req = new UnityWebRequest($"https://baidu.com");
//绕过SSL证书验证
req.certificateHandler = new BypassCertificate();
req.downloadHandler = new DownloadHandlerBuffer();
var asyncOp = req.SendWebRequest();
while (asyncOp.isDone == false)
{
await Task.Delay(1000 / 30); //30 hertz
}
var s = req.downloadHandler.text;
public static void testHttpClient()
{
HttpClient cli = new HttpClient();
var data = new JObject();
data["content"] = "hello";
Debug.Log(data.ToString());
var content = new StringContent(data.ToString(), Encoding.UTF8);
content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var resp = cli.PostAsync("https://weiyinfu.cn/jiahe/", content);
resp.Wait();
var sTask = resp.Result.Content.ReadAsStringAsync();
sTask.Wait();
var s = sTask.Result;
Debug.Log($"result= {s}");
}