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
1
Question by Siflou · May 27, 2015 at 03:40 PM · wwwjsonurl

Retrieving json with WWW raises 415 Unsupported Media Type

Hey Guys,

I've been using Uniweb for my web requests, but I had problem with iOS8 so I'm changing it back to plain WWW. I used it like so and it has worked when my content type is "application/x-www-form-urlencoded".

I used it like so :

 string myUrl ="someUrl.com/someFolder"
 WWWForm form = new WWWForm();
 form.AddField("Content-Type", "application/x-www-form-urlencoded");
 form.AddField("Content-length", "0");
 
 var headers = new Hashtable();
 headers.Add("WWW-Authenticate","xxxxx");
 
 WWW request = new WWW(url,form.data,headers);

It works fine but when I use it for content "application/json", I get the error 415 Unsupported Media Type. I read that I missed the Header "Accept", "application/json" so I tried to add it to the form and it didn't work than I added it to the headers and it didn't worked either.

Does anyone have an idea ?

Thanks a lot.

Comment
Add comment · Show 5
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 spiceboy9994 · May 27, 2015 at 04:48 PM 0
Share

What is the server platform that you're using as target for your requests? Is it IIs?

avatar image Siflou · May 27, 2015 at 05:45 PM 0
Share

No, its a Google app engine.

avatar image Ben-BearFish · Dec 31, 2015 at 02:08 AM 0
Share

@Siflou Did you find a solution for this? I'm having the same issue.

avatar image sandolkakos · Dec 31, 2015 at 04:05 AM 0
Share

Do you already have tried to send your request with other tool, like that bellow? https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo Always I get an error with Api requests in Unity, I like to test in this client tool in order to see if the error is in the unity code or in the data I am submiting.

avatar image Ben-BearFish · Jan 04, 2016 at 03:54 PM 0
Share

Yeah, an outside tool is actually the best way to tell if things are going wrong in Unity or in the actual web request itself. In my case, using the tool, I realized I was sending the wrong header. I'd recommend everyone uses a third party tool to confirm the validity of their requests. Postman is the tool I use, but anyone will do.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Giver · Jan 05, 2016 at 03:22 PM

I have solved this problem. You can try like this. //First , you need to convert your post data into byte[].

WWWForm form=new WWWForm(); string body=LitJson.JsonMapper.ToJson( /here is you data/ ); byte[] data=System.Text.Encoding.UTF8.GetBytes(body);

//then set the headers Dictionary headers=form.headers; headers["Content-Type"]="application/json";

WWW www=new WWW(url,data,headers);

You can try this.I have successed~ I feel good . hahaha

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 guneyozsan · Jan 31, 2017 at 12:20 AM 0
Share

I couldn't have this work until I defined headers variable as follows: Dictionary<string, string> headers = form.headers;

avatar image Bunny83 guneyozsan · Jan 31, 2017 at 04:05 AM 0
Share

He didn't mark his code as code so the angle brackets <> got stripped away as they are recognised as HT$$anonymous$$L tags.

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

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

Related Questions

Max String Length in WWW url's? 1 Answer

WWW.EscapeURL Not Work Well? 2 Answers

How to assign texture from url 1 Answer

Using WWW to simply post a slab of text .. ala JSON 2 Answers

Loaclization in WebGL? 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