Question

I'm using WWW to interact with a RESTful web service. I have a problem sending XML files to the server through POST requests, though. This is my code:

if(Syste.IO.File.Exists(filePath)){
    byte [] raw = File.ReadAllBytes(filePath);              
    WWWForm form = new WWWForm();
    form.AddBinaryData("fileUpload", raw, "", "text/xml");
    WWW www = new WWW(host + auth + "/behaviors", form);
    StartCoroutine(myCoroutine(www));
}

IEnumerator myCoroutine(WWW www){
    yield return www;

    if (www.error == null)
    {
        Debug.Log("Text: " + www.text);
        proceedToNextRequest = true;
    } else {
        Debug.Log("Error: "+ www.error);
        Application.Quit();
    }    
}

The answer from the server is, though, "Unsupported Media Type", and I've no idea what's wrong. I generally use POSTMAN on Google Chrome to send these requests, and it works fine. Any tips?

Was it helpful?

Solution

I have found a solution for this: instead of using the WWW class(which, anyway, according to the documentation I'm pretty sure it can be used for this pupose), I'm using WebRequest. How this can be achieved is very well explained in the previous link and in this question: HTTP post XML data in C#

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top