Note that there are some explanatory texts on larger screens.

plurals
  1. POAngular JS - can't receive any response using $http.post
    primarykey
    data
    text
    <p>I'm trying to get a response from a web service using Angular JS, which I can perfectly reach via my shell using a simple curl command: </p> <pre><code>curl --header "Content-type: application/json" --request POST --data '{"username": "name", "password": "pwd"}' 192.168.2.1:9000/ws/login </code></pre> <p><br> However, when I try to reach it using Angular with an <code>$http.post</code> I experience some "funny" behaviour.</p> <p>While my data are:</p> <pre><code> var url = "192.168.2.1:9000/ws/login" var postData = { username: un, password: pwd } </code></pre> <p><br> I've tried both <code>postData</code> as a JSON object and as a stringified JSON</p> <p>Using a call like this:</p> <pre><code> $http.post( url, postData ). success(function(data) { console.log(data) }). error(function(data, status, headers, config) { console.log(data, status, headers, config) }) </code></pre> <p>or even </p> <pre><code> $http({ url: url, method: 'POST', data: JSON.stringify(postData), headers: {'Content-type': 'application/json'} }). success(function(data, status, headers, config) { console.log('Success: ', data, status, headers, config) }). error(function(data, status, headers, config) { console.log('Error: ', data, status, headers, config) }) </code></pre> <p>Simply do nothing.<br> Nothing at all! <hr> Prepending an <code>http://</code> to the url instead, gives me:</p> <pre><code>OPTIONS http://192.168.2.1:9000/ws/login 404 (Not Found) angular.js:7073 OPTIONS http://192.168.2.1:9000/ws/login Origin http://localhost:9000 is not allowed by Access-Control-Allow-Origin. </code></pre> <p>I'm really really lost... any advice would be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload