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 jetese · Mar 14, 2019 at 09:18 AM · androidwwwdownloadwebrequestget

See Request of WWW or UnityWebRequest, 403 error only from android in a specific url (GET)

Hello, I have a code that downloads data from a url. I have a problem that one Url gives me error 403 (Forbidden) only from android. When i get the url from editor or Windows build, all works perfectly. So if i could see the Request that WWW or UnityWebRequest does from android and Windows i would be able to compare whats going wrong.

I tested it with two codes ( WWW and UnityWebRequest) and both give the same result. i tested it with other urls that contains xml, and it works.

Url: http://www.mambiente.madrid.es/opendata/horario.xml

WWW

 IEnumerator DownloadXml(string url, DateTime data = new DateTime())
     {
 
         WWW www = new WWW(url);
         yield return www;
 
         ParseXML text = new ParseXML();
         string file = www.text;

UnityWebRequest

 IEnumerator GetRequest(string url, DateTime data, bool actualPolution)
     {
         using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
         {
             // Request and wait for the desired page.
             yield return webRequest.SendWebRequest();
 
             if (webRequest.isNetworkError)
             {
                 Debug.Log(url + ": Error: " + webRequest.error);
             }
             else
             {
                 ParseXML text = new ParseXML();
                 string file = webRequest.downloadHandler.text;
                 Debug.Log(url + ":\nReceived: " + file);

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

2 Replies

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

Answer by xxmariofer · Mar 14, 2019 at 10:24 AM

after some test i have managed to retrieve the server data, had to add the accept info this code is tested and works for that site: (i have found a lot of different issues with sites from the Comunidad de Madrid)

     CookieContainer cookies = new CookieContainer();
     HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.mambiente.madrid.es/opendata/horario.xml");
     webRequest.UserAgent = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36";
     webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
     webRequest.Method = "GET";
     webRequest.CookieContainer = cookies;
     XmlDocument xmldoc = new XmlDocument(); 
     using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
     {
         using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))
         {
             string xml = streamReader.ReadToEnd();
             xmldoc.LoadXml(xml);
         }
     }
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 jetese · Mar 14, 2019 at 11:14 AM 0
Share

It works perfectly in android. I will try to adapt my code with this new information because i dont want to have two differents codes for the same task. If i dont get it i will use yours.

Thank you xxmariofer for your time.

avatar image
0

Answer by misher · Mar 14, 2019 at 09:55 AM

You should debug your android app, use logcat (for example, in Android Studio).

I suspect it to be related to the CORS problems. Make sure your server respond with: Access-Control-Allow-Origin:* header

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

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

Related Questions

Download progress is -1 forever. 2 Answers

Unity 5.6.7 - UnityWebRequest SSL/HTTPs 2 Answers

OutOfMemoryException when downloading files via the www class (iOS and Android) 1 Answer

Android can't download the audio 1 Answer

DownloadHandlerAudioClip compressed and streamAudio properties 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