Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 gardian06 · Feb 26, 2013 at 01:53 AM · wwwwwwform

what is needed to get WWW Post working correctly

I have been trying for some time to get server interaction between a server, and Unity set up. I can do pulls(GETs) fine, but POST just does not work.

my question is what is needed both in terms of unity code, and server to make POST work. what I think so far is this:

Unity needs to know the base url, and then I need to have Unity give post information (but what do I give it to? the server directly, or a specific script on the server?). then the server returns a response.

what do I need server side, and what do I need Unity side to get the WWW class fully functional (and the documentation is funny at best as I have looked and don't understand)

currently I just want to request a specific record see here for details

EDIT:

so I think I kind of understand, but correct this if it is wrong. in the server script there is to be a variable $inBoundData = $_POST["varName"];, and then in Unity I call out the post value string name with the WWWForm: form.AddField("varName, sentValue);

is this how I do this?

Comment
Add comment · Show 2
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 DaveA · Feb 26, 2013 at 01:57 AM 0
Share

Please post your code here in your question

avatar image gardian06 · Feb 26, 2013 at 12:09 PM 0
Share

@DaveA which code? (unity, or server)

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by gardian06 · Mar 01, 2013 at 04:11 PM

To answer this question actually requires some background: a certain amount of information must be known about the target server/page (what verbs it expects for what actions, and what direct actions are available by direct communication with the server.

the WWW class only allows access to 2 web verbs at time of writing (GET/POST). if the action that you are attempting to perform requires another verb (PUT/DELETE...) then an intermediary script must be placed on the target in order to accommodate for this "lacking" (the script must allow for interactions, but must be written in such a way that if a hacker targets it that no real harm can be done)

when interacting with a server, or such directly then it is possible to send similar to commandline information through headers (similar to the first post here (keep in mind that this is only for things that take the POST verb), and you might need to do trial, and error on the formatting that the server is expecting such as a server that expects json for POST quarries may not take exactly formatted json, but it might be close. Such as mongodb for a POST request of data takes:

string rqData = "{searchField:\\""+searchKey+"\\"}";

when interacting with a script directly usually using the WWWForm class if there is only one script on the server then you do not absolutely need to call out the script specifically though my suggestion is to target the script directly unless you absolutely know that you don't have to. in order to target a script directly (besides having the url go directly to that script) you need to know the signal word that the script expects for post data. when reading through say a php script these will be $_POST["singalWord"] and when constructing the form data through WWWForm.AddField() it would be AddField("signalWord", providedData) then just send the form with the WWW construtor. similar security considerations need to be given for these interaction as it is quite possible that interacting directly with a script on a server can supersede the securities of the server.

Comment
Add comment · 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
0

Answer by DaveA · Feb 26, 2013 at 01:59 AM

It needs the url to the script on the server. Ex: http://yourdomain.com/scripts/yourscript.php

The server needs to access the POST variables, ex: $_POST['myfield']

Comment
Add comment · Show 4 · 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 gardian06 · Feb 26, 2013 at 02:03 AM 0
Share

so do I need to write a specific script for the server, or do I need to do some kind of config file for the server? this is the part that is confusing me (because just giving it a url to do a simple GET is fine. it is only the post the fails)

avatar image Jeremy Hindle · Feb 26, 2013 at 12:14 PM 0
Share

Id personally set up json or xml parsing at each end. just to simplify things and allow you to send larger amounts of information more easily.

avatar image gardian06 · Feb 26, 2013 at 12:45 PM 0
Share

Ok, but like in @DaveA answer would this be in a script I call by name (like here in code box4), or would I just call the server, and have it wary about it? what is the overall difference in these approaches from Unity/server?

avatar image gardian06 · Feb 26, 2013 at 03:51 PM 0
Share

so I think I kind of understand, but correct this if it is wrong. in the server script there is to be a variable $inBoundData = $_POST["varName"];, and then in Unity I call out the post value string name with the WWWForm: form.AddField("varName, sentValue);

is this how I do this?

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Getting info using WWW & PHP 3 Answers

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

WWW/WWWForm, does Unity validate SSL certificates? 1 Answer

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

How to use POST service using www class? 0 Answers


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