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 scarpelius · Feb 23, 2014 at 02:07 PM · wwwwwwform

WWW+WWWForm 500 Internal Server Error

I am trying to send data to a webserver via WWWForm but I get this error. Looking into apache logs, I can see unity accessing the requested page but there is no error in logs. The server side code is ok, I've tested it with a GET from unity and is doing what is suppose to do. But when I switch to sending data with wwwform via POST I get "500 Internal Server Error" no matter what i do.

Using GET like this WWW www = new WWW(url + "?field1="+value1+"&field2=value"+"&field3="+value3); works as intended without any error.

Here is a test I've done outside of my game:

 using UnityEngine;
 using System.Collections;
 
 public class senddata : MonoBehaviour
 {
     private bool once = false;
     WWW www = null;
 
     void OnGUI()
     {
         if (GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 20, 200, 40), "Send"))
         {    
             StartCoroutine("Send");
         }
 
 
     }
 
     IEnumerator Send()
     {
         WWWForm form = new WWWForm();
         form.AddField("f1", "value 1", System.Text.Encoding.UTF8);
         form.AddField("f2", "value 2", System.Text.Encoding.UTF8);
         form.AddField("f3", "value 3", System.Text.Encoding.UTF8);
         www = new WWW("obscured", form);
 
         yield return www;
 
         if(!string.IsNullOrEmpty(www.text) && !once)
         {
             Debug.Log(www.text);
             once = true;
         }
     }
 }
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

3 Replies

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

Answer by scarpelius · Feb 23, 2014 at 06:36 PM

I will answer myself to this since I found the problem. I use Codeigniter framework on the server side and this had the Cross Site Request Forgery and Global XSS Filtering on. Disabling them removed my problem.

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
1

Answer by stijnvdbBiodroid · Mar 09, 2015 at 01:03 AM

Spent some time on this same issue, framework was Laravel 5.0. Laravel uses csrf tokens to prevent cross-site request forgeries, you can disable that by editing app/Http/Kernel.php, commenting out this line:

 'App\Http\Middleware\VerifyCsrfToken',

Hope this helps someone.

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 shaneparsons · Jun 03, 2016 at 02:12 PM 0
Share

Is there a way to use the CsrfToken rather than disabling it?

avatar image
0

Answer by fazhom · Feb 08, 2016 at 02:22 PM

If I understand correctly: both these solutions deactivate a security check on the frameworks.

I'm using Laravel and I wanted to keep the security active except for a few routes requested by my Unity game.

It would seem that Laravel offers this possibility (as described in Excluding URIs From CSRF Protection) but after many tests it didn't seem to work. Looking at the code, I'm not sure the $except var is used by the framework...

I found this solution wich does the trick.

Basically, rewrite the handle() funcion in App\Http\Middleware\VerifyCsrfToken.php so that it takes the $except var into account. Beware if you copy their code paste, they renamed $except to $except_urls.

 public function handle($request, Closure $next) {

         $regex = '#' . implode('|', $this->except_urls) . '#';
         if ($this->isReading($request) || $this->tokensMatch($request) || preg_match($regex, $request->path()))
         {
             return $this->addCookieToResponse($request, $next($request));
         }
 
         throw new TokenMismatchException;
     }

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

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

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

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 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