Quantcast
Channel: Questions in topic: "webrequest"
Viewing all articles
Browse latest Browse all 387

How to use the new IMultipartFormSection in a UnityWebRequest.Post

$
0
0
I'm new to online interaction and after successfully running a local server with Visual Studio Code I tried to Get/Post from within a unity project, I was able to use Get just fine, but I've been having trouble getting Post working with the IMultipartFormSection. I tried it with the WWWForm and that worked like a charm, but I would rather use the latest and greatest from unity. The code I'm running in Mono, mostly taken from the documentation, is as fallows       IEnumerator Start () {         List formData = new List();        formData.Add( new MultipartFormDataSection("_userName=ema&_passWord=car") );         formData.Add( new MultipartFormFileSection("my file data", "myfile.txt") );         UnityWebRequest www = UnityWebRequest.Post("http://localhost:5000/api/test", formData);         yield return www.SendWebRequest();         if(www.isNetworkError || www.isHttpError) {             Debug.Log(www.error);         }         else {             Debug.Log("Form upload complete!");         }     } But it always gives me a Generic/unknown HTTP error. The post request that is listening in Visual Studio Code is [HttpPost] public string Post(string _userName, string _passWord) { var filter = Builders.Filter.Eq(x => x.name, _userName) & Builders.Filter.Eq(x => x.password, _passWord); var document = _collection.Find(filter).FirstOrDefault(); if (document != null){ return "That is already an account"; } else{ _collection.InsertOne(new Data(_userName, _passWord)); return "Profile created"; } } Any help or suggestions would be greatly appreciated, alternatively a link to a video or tutorial that explains ImultipartFormSection and how to use it would be nice.

Viewing all articles
Browse latest Browse all 387

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>