2

using curl I can send a POST request to

"http://myusername:mypassword@SomeURL" to trigger an action

Using xml http request I've tried doing the same thing but running the following code:

  xhttp = new XMLHttpRequest();
  xhttp.open("POST", "http://myusername:mypassword@SomeURL", true);
  xhttp.setRequestHeader("Content-Type", "text/plain");
  xhttp.send();

Greets me with the error:

POST http://myusername:mypassword@SomeURL 403 (Forbidden)

Now why would this be ? Is accessing an url like this via a browser, curl, arc... etc different from accessing it via .js ? Furthermore I've tried posting to said url using the action of a form and it worked swimmingly, but I'd prefer to get things done in JavaScript if possible for this specific task.

So... ahm, any ideas ? The documentation behind the XMLHttpRequest that i've seen has been rather lack-luster for a technology that "carries the modern web upon its shoulders".

George H
  • 412
  • 3
  • 6
  • 12
  • CURL is a get call I guess, besides I did not understand the usage of **:** in the url that you are requesting – Akshay Khandelwal Jul 04 '16 at 09:32
  • the specific API I'm calling read those header as being a username and a password, it uses the ':' to see where the split is (or at least I assume that's what it does). Think of the myusername:mypassword as being a single "user" header. – George H Jul 04 '16 at 09:59

2 Answers2

0

Necessary reading to solve this question:

I am deliberately not adding a code sample; the linked questions have everything you need.

Community
  • 1
  • 1
Tomalak
  • 332,285
  • 67
  • 532
  • 628
0

Sounds like you might need to enable CORS (cross-origin resource sharing)

Yvonne Aburrow
  • 2,602
  • 1
  • 17
  • 47