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 Nikesh78 · Apr 20, 2017 at 09:01 AM · networkjsonwwwformform

REST API Response Error: 406 - not acceptable

enter code hereHi , I am using PHP on server side & the api that I want to use is successfully tested on POSTMAN. The api works in both form-data & raw under body.

I am unable to get response for the simple POST method API of php from UNITY. I have mess up with : unityWebRequest, WWForm. WWW .

Kindly please review my sample code .

 using System;
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.Networking;
 
 
 public class Postwa : MonoBehaviour
 {
     void Start()
     {
         StartCoroutine(Upload());
     }
 
     IEnumerator Upload()
     {
         WWWForm form = new WWWForm();
         form.AddField("licenseKey", "12345678");
         Debug.Log(form.data.ToString());
         
         using (UnityWebRequest www = UnityWebRequest.Post("https://mindplugged.com/space/methodName", form))
         {
            
             yield return www.Send();
 
             if (www.isError)
             {
                 Debug.Log(www.error);
             }
             else
             {
             
                 Debug.Log(www.responseCode.ToString());
                 Debug.Log(www.downloadHandler.text);
             }
         }
     }
 
 }



Thanks in Advance

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
5

Answer by Aelcyx · Oct 05, 2017 at 09:24 PM

I found that adding these headers made it work:

  headers.Add("Accept", "*/*");
  headers.Add("Accept-Encoding", "gzip, deflate");
  headers.Add("User-Agent", "runscope/0.1");

I figured this out by going to hurl.it, trying the request there and then looking at the response data via browser tools.

Comment
Add comment · Show 2 · 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 JeffScm · Nov 21, 2017 at 10:42 AM 0
Share

It works for POST but for GET and Asset bundles you need to upgrade to UnityWebRequest like this:

 var www = UnityWebRequest.GetAssetBundle("https://...");
 www.SetRequestHeader("Accept", "*/*");
 www.SetRequestHeader("Accept-Encoding", "gzip, deflate");
 www.SetRequestHeader("User-Agent", "runscope/0.1");
 yield return www.SendWebRequest();
 

avatar image bob2unlimited · Nov 03, 2018 at 06:39 AM 0
Share

Thank you for this. Was on this for hours. The issue was the User-Agent from my end. Server was saying $$anonymous$$od Security was blocking the calls.

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

7 People are following this question.

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

Related Questions

What exactly does the wwwform.addfield do exactly? 0 Answers

Get o Post method without open browser 1 Answer

How do I use WWWform and JSON to login to reddit? 1 Answer

Use the data received from WWW in UI 1 Answer

Network issue. Weird problem resolving host 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