usingUnityEngine;
usingSystem.Collections;
usingUnityEngine.Networking;
usingSystem.Collections.Generic;
publicclassPostStr:MonoBehaviour{
//http://192.168.10.10:8080/users
string url="http://192.168.10.10:8080/users";
//username=zhangsan pwd=123456
voidStart( ){
StartCoroutine("Post_Login");
}
voidUpdate( ){
}
IEnumeratorPost_Login( ){
//1.
//List<IMultipartFormSection>formData=newList<IMultipartFormSection>( );
//formData.Add(new MultipartFormDataSection("username","zhangsan"));
//formData.Add(new MultipartFormDataSection("psd","123456"));
//formData.Add(new MultipartFormDataSection("username=zhangsan","psd==123456"));
//2.
//WWWForm form=new WWWForm();//要传给服务器的参数
//form.AddField("username","zhangsan");
//form.AddField("pwd","123456");
//form.AddBinaryData( );//上传图片给服务器
//WWWwww=newWWW(url,form);
//3.
Dictionary<string,string>dic=new Dictionary<string,string>( );
dic.Add("username","zhangsan");
dic.Add("pwd","123456");
UnityWebRequest wr=UnityWebRequest.Post(url,dic);
wr.downloadHandler=new DownloadHandlerBuffer();
yield return wr.Send();
//UnityWebRequestwr=UnityWebRequest.Post(url,form);
//wr.downloadHandler=newDownloadHandlerBuffer();
//yieldreturnwr.Send();
if(!wr.isError){
print(wr.downloadHandler.text);
}
}
}