- Home /
How can i pass the post data of a server side page to unity?
I have a game loading page that has post data associated with it. I'm using an ASP.Net page and need this data to be POST data, it can't be GET data (as in data in url parameters).
I looked at a few samples but none seem to clearly do what i'm trying to do. In short, a player for my game would be able to select a server, but the web page has in its POST data the ip and port to connect to so they can join the server.
I tried setting a js var in a script (using syntax, but its unclear how to pass it to unity or to have unity pull it. I looked at a PlugIn sample, but that seems to be overkill for my needs and not clear if/when i can pass it the data.
Its probably simple but i can't figure it out.
Use WWW Class. Example:
IEnumerator $$anonymous$$ethodA(){
byte[] postData=new byte[](0,1,2,3,4,5);
yield return new WWW("url",postData);
}
You are getting confused, i don't want to pass data from Unity to a Server. What i want to do is forwarding the POST data that is part of the web request from my file which is a server side page (ASP/ASP.NET/PHP/CGI etc). The values passed in the POST data is the information that Unity $$anonymous$$odules need to receive.
1) Player goes to my game website
2) Player picks one server from a list of server and clicks on its "PLAY NOW" link button.
3) The "PLAY NOW" link button now makes the browswer load a page similar to index.html but this is a server side page with which some data is provided in the POST portion of the headers. This is identical to GET parameters, but those values don't show on the URL.
4) This is where i'm confused ... i want those parameters to be used or accessed by Unity but i don't know or understand how to pass them to Unity.
First don't exist a "POST portion of the headers" there is only the URL, the Headers and the Binary Content Data.
In a GET Request you send the URL and the Headers to receive Headers and Binary Content Data. In a POST Request you send the URL and the Headers and the Binary Content Data to receive Headers and Binary Content Data.
If you need send Data to a URL you need use The WWW class. If you need send a GET request you can use new WWW("url")
. If you need send a POST request you can use new WWW("url", byteArray)
or use new WWW("url", byteArray, headersHastableOrDicionary)
or use with a WWWForm Classnew WWW("url",form)
.
if you need receive Data from a URL independent if it is a POST or a GET request you need use a WWW.bytes to get the Binary Content Data and a WWW.responseHeaders to get the Headers
if you are using WebGL and need communicate with the browser see WebGL: Interacting with browser scripting.
if you are using WebPlayer and need communicate with the browser see Unity Web Player and browser communication.
If this don't resolve your problem, then you problem is not related to HTTP web request.
Answer by elenzil · Nov 23, 2016 at 12:13 AM
sergio is correct: there's no such thing as POST headers vs GET headers: there's just headers. you're probably thinking of passing parameters via POST body instead of via URL. that's fine.
but the post is a request to the server, and the page which has your unity in it is the response. they're separate, and there's not an automatic mechanism for getting params (URL or POST) echo'd in the response. it entirely depends on the server.
what it sounds like you should do is modify your server-side code so that the parameter you care about is re-emitted as javascript code in the response, and then on the client-side (aka the browser) you can funnel the values into unity.
Thanks for the Answer, you seem to grasp better what i'm trying to do.
As i said to Sergio, and i appreciate that he tried to help, i probably expressed myself the wrong way,
So, I can do the server side to JS. now, how do i funnel those values to be used by my unity game so that it can connect using WebGL/WebSockets to connect to my game server ?
Your answer
![](https://koobas.hobune.stream/wayback/20220612100947im_/https://answers.unity.com/themes/thub/images/avi.jpg)