Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by darkbytepod · Nov 19, 2016 at 07:03 AM · datahtmlpostserverside

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.

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sergio7888 · Nov 19, 2016 at 11:36 PM 0
Share

Use WWW Class. Example:

 IEnumerator $$anonymous$$ethodA(){
     byte[] postData=new byte[](0,1,2,3,4,5);
     yield return new WWW("url",postData);
 }


avatar image darkbytepod Sergio7888 · Nov 20, 2016 at 08:15 AM 0
Share

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.

avatar image Sergio7888 darkbytepod · Nov 20, 2016 at 08:50 PM 0
Share

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.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image darkbytepod · Nov 25, 2016 at 06:16 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I make a simple POST request to Amazon S3? 2 Answers

Split string data 0 Answers

How to Upload multiple files to a server using UnityWebRequest.Post(); 3 Answers

How to Pass a Json as Post Data to WWWForm 2 Answers

How to create an agenda or timetable system? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges