hate these ads?, log in or register to hide them
Page 117 of 121 FirstFirst ... 1767107114115116117118119120 ... LastLast
Results 2,321 to 2,340 of 2407

Thread: <xml><thread isTerrible="true" isUnderstandable="false" /></xml> - Coding help thread

  1. #2321
    NoirAvlaa's Avatar
    Join Date
    April 12, 2011
    Location
    Liverpool, laaaa
    Posts
    4,311
    Kotlin is now a first class language for Android, supported by Google and built in to Android Studio 3.0

  2. #2322

    Join Date
    April 14, 2011
    Posts
    5,530
    Interestingly they're also going to set up the "Kotlin Foundation" to "shepherd the language", but no mention of transfer of ownership. Until that happens it's still a tough sell for many.

  3. #2323
    Donor Aea's Avatar
    Join Date
    April 13, 2011
    Location
    Colorado
    Posts
    13,911
    Thread almost fell off the page...

    https://hackernoon.com/jokes-program...d-23d484d8bef8

  4. #2324
    Movember 2012 I Legionnaire's Avatar
    Join Date
    April 9, 2011
    Posts
    1,610
    Elixir is cool.

  5. #2325
    Movember 2012 I Legionnaire's Avatar
    Join Date
    April 9, 2011
    Posts
    1,610

  6. #2326
    Donor halbarad's Avatar
    Join Date
    April 9, 2011
    Posts
    4,805
    I've got a JS problem if anyone can help me. I know just enough JS to be able to read some of it and hack bits and pieces of code together but beyond that I'm a bit stuck.

    I’m trying to do a call to a REST api using JS. I’ve got the following code:
    Code:
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", $TargetURL, false);
            xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
            xmlhttp.withCredentials = true;
            xmlhttp.setRequestHeader("Content-Type", "application/json");
            xmlhttp.setRequestHeader('Authorization', 'Basic ' + window.btoa('<token>:'));
            xmlhttp.send();
    Which throws an error 405, needing me to set Access-Control-Allow-Origin header but I’ve got it set. Looking in the console in FireFox or Chrome shows me that all the headers are being turned into plain text and added to a single header value:

    Code:
    Access-Control-Request-Headers: "access-control-allow-origin,authorization,content-type"
    All the examples I can find online suggest I should be able to do this as it is and it should work. I’ve tried removing the other headers apart from access-control-allow-origin and that still ends up the same way.

    Is there a better way to call a REST api in JS? Is there something obvious I’ve missed with this? It’s going to be running in VSTS so has jquery and a few other libraries available should they be needed.

  7. #2327
    Movember 2012 I Legionnaire's Avatar
    Join Date
    April 9, 2011
    Posts
    1,610
    Not sure why your headers are being concat'd like that but afaik 'fetch' is the modern way to do api calls.

    https://developer.mozilla.org/en-US/...PI/Using_Fetch

    If you need IE compatibility, include these two in your project.

    promise polyfill
    fetch polyfill

  8. #2328
    Daneel Trevize's Avatar
    Join Date
    April 10, 2011
    Location
    T L A
    Posts
    12,024
    https://developer.mozilla.org/en-US/...tRequestHeader
    For your custom fields, you may encounter "not allowed by Access-Control-Allow-Headers in preflight response" exception when you send request to cross domain. In this situation, you need set "Access-Control-Allow-Headers" in your response header at server side.
    Is your target server sending out the header to tell the browser it's happy to accept the rest of your headers & requests in this scenario?
    Or am I misreading that totally?
    Last edited by Daneel Trevize; September 5 2017 at 09:31:57 PM.
    Quote Originally Posted by QuackBot View Post
    Idk about that, and i'm fucking stupid.

  9. #2329
    Donor halbarad's Avatar
    Join Date
    April 9, 2011
    Posts
    4,805
    Someone else mentioned that too so I've got to look at sorting that out tomorrow.

    I'll also look into the Fetch method as well.

  10. #2330
    Donor Aea's Avatar
    Join Date
    April 13, 2011
    Location
    Colorado
    Posts
    13,911
    https://stackoverflow.com/questions/...ing-my-headers


    Sent from my iPhone using Tapatalk

  11. #2331

    Join Date
    April 14, 2011
    Posts
    5,530
    Quote Originally Posted by halbarad View Post
    I know just enough JS to be able to read some of it and hack bits and pieces of code together
    Aha, a javascript developer!

  12. #2332

    Join Date
    April 14, 2011
    Posts
    5,530
    Quote Originally Posted by halbarad View Post
    I know just enough JS to be able to read some of it and hack bits and pieces of code together
    Aha, a javascript developer!

  13. #2333
    NoirAvlaa's Avatar
    Join Date
    April 12, 2011
    Location
    Liverpool, laaaa
    Posts
    4,311
    Quote Originally Posted by elmicker View Post
    Quote Originally Posted by halbarad View Post
    I know just enough JS to be able to read some of it and hack bits and pieces of code together
    Aha, a javascript developer!
    Dunno, he seems overly qualified for that role...

    Sent from my Nexus 5X using Tapatalk

  14. #2334
    Super Moderator Global Moderator QuackBot's Avatar
    Join Date
    March 7, 2012
    Posts
    20,879
    Quote Originally Posted by Daneel Trevize View Post
    Is your target server sending out the header to tell the browser it's happy to accept the rest of your headers & requests in this scenario?
    Or am I misreading that totally?
    Huh? Only limit for such a civ is how much energy they can get. Dyson sphere gives you all the headers.

  15. #2335
    Super Moderator Global Moderator QuackBot's Avatar
    Join Date
    March 7, 2012
    Posts
    20,879
    Quote Originally Posted by NoirAvlaa View Post
    Kotlin is now a first class language for Android, supported by Google and built in to Android Studio 3.0
    The first is something like this in it.

  16. #2336
    Donor halbarad's Avatar
    Join Date
    April 9, 2011
    Posts
    4,805
    Quote Originally Posted by elmicker View Post
    Quote Originally Posted by halbarad View Post
    I know just enough JS to be able to read some of it and hack bits and pieces of code together
    Aha, a javascript developer!
    Don't let my boss know that, I'm happy doing PowerShell and other stuff and staying as far from JS as I can.

    Quote Originally Posted by Daneel Trevize View Post
    https://developer.mozilla.org/en-US/...tRequestHeader
    For your custom fields, you may encounter "not allowed by Access-Control-Allow-Headers in preflight response" exception when you send request to cross domain. In this situation, you need set "Access-Control-Allow-Headers" in your response header at server side.
    Is your target server sending out the header to tell the browser it's happy to accept the rest of your headers & requests in this scenario?
    Or am I misreading that totally?
    Turns out the server (SonarQube) doesn't support CORS and they don't intend to support it. Their solution is to either use a reverse proxy or run the code server side, both of which would be a massive pain for what I want to do.

  17. #2337

    Join Date
    April 14, 2011
    Posts
    5,530
    Doesnt sonar just run inside an embedded tomcat or something? It's up to its container to support cors rather than sonar itself

  18. #2338
    Donor halbarad's Avatar
    Join Date
    April 9, 2011
    Posts
    4,805
    Quote Originally Posted by elmicker View Post
    Doesnt sonar just run inside an embedded tomcat or something? It's up to its container to support cors rather than sonar itself
    It's running on a java webserver sadly. If I could host it on anything else then I would happily do that.

  19. #2339

    Join Date
    April 14, 2011
    Posts
    5,530
    Yeah but that's what i mean - all the major java web servers support some form of cors. unless they're running something ancient or very custom or barebones (or some combination of all three) there'll be a web.xml file or similar you can specify a Filter to handle cors

  20. #2340
    Donor erichkknaar's Avatar
    Join Date
    April 10, 2011
    Posts
    8,976
    Quote Originally Posted by halbarad View Post
    Turns out the server (SonarQube) doesn't support CORS and they don't intend to support it.
    wat?
    meh

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •