I’m currently working on a web app that needs to acquire information from an online database. I’m trying to access a SOAP web service with an HTTP POST request using XML. So far I’ve been trying to use WWW and WWWForm class to do this, but I haven’t been able to find any proper examples to guide me. Does anyone have an example or ideas (or some thread that’s already been answered that I did not see) to send an HTTP POST request in properly formed XML within Unity Javascript?
I am not at my pc right now but I will post some code when I get in today. The WWW class has an overloaded method to call a URL and allows you to pass in a hashtable of HTTP header values and I think a string or some data bytes. Works perfect with our web services. Again sorry for the lack of solid memory set it up a while ago and haven’t thought much of it since.
So I got everything working, the code is sending and receiving information from the online database, however, when I built the program to a web player, it did not send out the request, or there was no response (not sure where I would check this at).
So is there a different way to do HTTP POST requests if you’re working inside a web player? or something that needs to be altered? here is a sample of my code for the request, maybe it just involves tweaking something to work outside of the unity editor.
static function GetUserToken ()
{
var encoding = new System.Text.UTF8Encoding();
var postHeader = new Hashtable();
var xmlPostData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" +
"<GetUserToken xmlns=\"http://ws.historicaloptiondata.com/\">" +
"<LogonId>" + userName + "</LogonId>"+
"<Password>" + password + "</Password>" +
"</GetUserToken>" +
"</soap:Body>" +
"</soap:Envelope>";
postHeader.Add("Content-Type", "text/xml");
postHeader.Add("Content-Length", xmlPostData.Length);
postHeader.Add("SOAPAction", "http://" + HOSTADDRESS + "/GetUserToken");
return new WWW(HOSTADDRESS, encoding.GetBytes(xmlPostData), postHeader);
}
I talked to a fellow programmer and he mentioned to me where to find it in the Console logs. the error I was receiving was:
You are trying to load data from a www stream which had the following error when downloading.
Failed downloading ws.historicaloptiondata.com
UnityEngine.WWW:get_data()
UnityEngine.WWW:get_data()
not too descriptive. I wasn’t sure if there is some sort of security issues I have to disable to allow data streams or something. or if there is something the website would need to change on their end to allow website streaming data.