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 vikhi · Mar 21, 2013 at 06:27 AM · wwwphpwwwform

WWWForm.Addfield not able to post data to server

I need to post data to a server. The server connection is made . But data is not posted in the server. I have correct script in curl/php. But its equivalent WWWform.Addfield is not working properly.

php script:

 $oauth_consumer_key = 'mvKm39WrNkp4enY2Ufk5nnJ5qqoLoPkC'; 
                 $oauth_token = 'BYUTPDgspPDHiGcppXRtRqC7btBbKqGS';
                 session_start();
                 global $user;
                 $username = trim("visvanathan-a");
                 $password = trim(base64_encode("------@3620"));
                 $ch = curl_init(); 
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($ch, CURLOPT_POST, 1);
                 curl_setopt($ch, CURLOPT_URL, 'http://10.98.12.54/sandbox/services/json?oauth_consumer_key='.$oauth_consumer_key.'&oauth_token='.$oauth_token.'');
                 $data = 'method="user.login"&username="'.$username.'"&password="'.$password.'"&domain="HCLTECH"';
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                 $result = curl_exec($ch);
                 $res = json_decode($result,true);
                 echo "Test Call ---- ";
                 print_r($res);
 
 
 
 

My equivalent unity Script

 #pragma strict
 import System.IO;
 import System.Text;
 import System;
 
 private  var str : String ="";
 private var url = "http://10.98.12.54/sandbox/services/json?oauth_consumer_key=GGCbkzxLMCtwtCFjXPrjpdu98Xnj7QUy&oauth_token=xMZZMByTY5aL94ARqcASqEp4o7QEvKSz";
 
 function Start () 
 
 {
 
   var form= new WWWForm();
 form.AddField("method","user.login"+);
 form.AddField("username","vigneshwari.ramu");
 form.AddField("password","sasffgfhhhhj");
 form.AddField("domain","HCLTECH");
 
   
     var hs_post = WWW(url,form.data);   
     yield hs_post; 
     if(hs_post.error) 
     {       
     print("There was an error posting the high score: " + hs_post.error); 
     }
     
     str = hs_post.text;
     print(str);
 
 }

Please say what problem in my unity code. why iam not able post username, password and domain

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

1 Reply

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

Answer by XienDev · Mar 21, 2013 at 06:50 AM

before post add this code:

         var headers = form.headers;
         
         if (!headers.Contains("Content-Type"))
         {
             headers.Add("Content-Type", "application/x-www-form-urlencoded");
         }
                 
         
          var hs_post = new WWW(url, form.data, headers);


That solved my problems =)

2) have you added crossdomain.xml ?

Comment
Add comment · Show 10 · 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 vikhi · Mar 21, 2013 at 06:58 AM 0
Share

@XienDev I tried what you said . Still its not working In the server log

$$anonymous$$ethod = userlogin -> this got posted But remaining

username = "" password = "" domain = ""

is not getting posted . Its showin nothing in the server log for these fields.

I get output as

{ "#error": true, "#data": "Invalid method " }

But I should be getting output as

[#error] => [#data] => stdClass Object ( [sessionid] => gnCgd3$$anonymous$$bwbqBe96_k$$anonymous$$2R15_Ar5-umb$$anonymous$$lqZc [user_id] => 25452 [user_first_name] => Visvanathan [user_last_name] => Arumugam [photo_url] => http://localhost/$$anonymous$$E$$anonymous$$E/sites/default/files/pictures/picture-25452-142550.jpg )

When my metho field gets posted why not my username, poassword, domain field not posted in server?

avatar image vikhi · Mar 21, 2013 at 07:05 AM 0
Share

XienDev

No I have not added crossdomain.xml

Iam trying to post data to server and get a response Iam new to this. The php script given above works fine in posting and retrieving response from sever But my equivalent unity script shows error . Connection made but post unsuceessful to server

avatar image vikhi · Mar 21, 2013 at 07:07 AM 0
Share

@XienDev

No I have not added crossdomain.xml

Iam trying to post data to server and get a response Iam new to this. The php script given above works fine in posting and retrieving response from sever But my equivalent unity script shows error . Connection made but post unsuceessful to server

avatar image vikhi · Mar 21, 2013 at 07:08 AM 0
Share

@XienDev

content type and application/x-www-form-urlencoded refers to what? Sorry Iam newbie at this

avatar image XienDev · Mar 21, 2013 at 07:44 AM 0
Share

Post here, please, your server's response headers

Show more comments

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

Retrieving varibale values from a php script? 1 Answer

WWW Class is acting up 1 Answer

Why isn't this $_POST working properly? 1 Answer

wwwform send an array the right way! 0 Answers

Would a WWW to a PHP file return the computers Info? 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