$http.get not sending data in request body


winner

While using angular v1.3.1, I'm having the following problem trying to implement a facade for making http requests to a REST+JSON interface in the backend of a web application.

I get something like this in the code:

findSomething(value: number): ng.IPromise<api.DrugIndication[]> {
  const getParams = { 'param' : 'value' };
  const config:ng.IRequestShortcutConfig = {
    headers: {
      "Content-Type" : "application/json"
    },
    data: getParams
  }
  return this.$http.get(url,config);
}

When it needed to be called, I got a 400 Bad Request (btw: a great name for a band!) because the backend (made by Play for Scala) immediately rejected the request. So when checking in the request, I see that no data is sent in the request/message body.

So, how can I send some data in the body of HTTP using angular "$http.get"?

Additional info: This doesn't happen if I make a make request using the curl command from the ubuntu shell . So there might be a problem between Chrome and angular.js

Peter

If you check the "Network" tab in chrome dev tools, you'll see that this is a pre-flight OPTIONS request (Cross Origin Resource Sharing (CORS)).

You have two ways to solve this problem.

  1. Client (this requires your server not to need application/json values)

    • GET, POST, HEAD methods only
    • Only browser settings headers plus these
    • Content types only have:
      • application/x-www-form-urlencoded
      • multipart/form-data
      • text/plain text
  2. Service-Terminal

    • Set something like this as middleware on the server framework:

      if r.Method == "OPTIONS" {
          w.Header().Set("Access-Control-Allow-Origin", "*")
          w.Header().Set("Access-Control-Allow-Methods", "GET")
          w.Header().Set("Access-Control-Allow-Headers", "Content-Type,Authorization")
          w.Header().Set("Access-Control-Max-Age", "86400") // firefox: max 24h, chrome 10min
          return
      }
      

For your specific framework this should work

Related


$http.get not sending data in request body

winner While using angular v1.3.1, I'm having the following problem trying to implement a facade for making http requests to a REST+JSON interface in the backend of a web application. I get something like this in the code: findSomething(value: number): ng.IPro

$http.get not sending data in request body

winner While using angular v1.3.1, I'm having the following problem trying to implement a facade for making http requests to a REST+JSON interface in the backend of a web application. I get something like this in the code: findSomething(value: number): ng.IPro

$http.get not sending data in request body

winner While using angular v1.3.1, I'm having the following problem trying to implement a facade for making http requests to a REST+JSON interface in the backend of a web application. I get something like this in the code: findSomething(value: number): ng.IPro

$http.get not sending data in request body

winner While using angular v1.3.1, I'm having the following problem trying to implement a facade for making http requests to a REST+JSON interface in the backend of a web application. I get something like this in the code: findSomething(value: number): ng.IPro

Unable to get request body by resify sending data using Postman

Derek I am using Restify server (node version is v9.11.1, restify version is 6.4.0). Here is my server configuration: server.use(restify.plugins.queryParser({ mapParams: true })) server.use(restify.plugins.bodyParser({ mapParams: true })); server.pre(restify

HTTP GET with request body

flip I am developing a new RESTful web service for our application. When performing a GET on some entities, the client can request the content of the entity. If they want to add some parameters (for example, sort the list), they can add those parameters in the

http get body request

tmnd91 I know you shouldn't send HTTP GET requests with a body, but the ceilometer Web API forces me to. I'm developing a ceilometer scala client, so I need a scala/java way to make a get request to the body. So far I tried using beeClient ( http://www.bigbeec

HTTP GET with request body

flip I am developing a new RESTful web service for our application. When performing a GET on some entities, the client can request the content of the entity. If they want to add some parameters (for example, sort the list), they can add those parameters in the

http get body request

tmnd91 I know you shouldn't send HTTP GET requests with a body, but the ceilometer Web API forces me to. I'm developing a ceilometer scala client, so I need a scala/java way to make a get request to the body. So far I tried using beeClient ( http://www.bigbeec

HTTP GET with request body

flip I am developing a new RESTful web service for our application. When performing a GET on some entities, the client can request the content of the entity. If they want to add some parameters (for example, sort the list), they can add those parameters in the

Rectangular DELETE request, sending data in the body

Sergey Tyupaev I am using restangular to send DELETE request. I send some data in the request and add the data to the query string. But I want to use body instead of URI. I found this question on stackoverflow . This problem can be solved by using methods , Mg

Rectangular DELETE request, sending data in the body

Sergey Tyupaev I am using restangular to send DELETE request. I send some data in the request and add the data to the query string. But I want to use body instead of URI. I found this question on stackoverflow . This problem can be solved by using methods , Mg

Rectangular DELETE request, sending data in the body

Sergey Tyupaev I am using restangular to send DELETE request. I send some data in the request and add the data to the query string. But I want to use body instead of URI. I found this question on stackoverflow . This problem can be solved by using methods , Mg

Rectangular DELETE request, sending data in the body

Sergey Tyupaev I am using restangular to send DELETE request. I send some data in the request and add the data to the query string. But I want to use body instead of URI. I found this question on stackoverflow . This problem can be solved by using methods , Mg

HTTP GET with request body RETROFIT

user2026760: I am using Retrofit to make api calls in my android application. I have to submit JSON @Body @GET("api/") void getData(@Body UserPostRequestBody request) I get the error message retrofit.RetrofitError: apiCall: Non-body HTTP method cannot contain

HTTP GET with request body RETROFIT

user2026760: I am using Retrofit to make api calls in my android application. I have to submit JSON @Body @GET("api/") void getData(@Body UserPostRequestBody request) I get the error message retrofit.RetrofitError: apiCall: Non-body HTTP method cannot contain

Dart - Http Get request with body

User 11688660 I want to send HTTP GET request with json body using dart. I know it's possible because I've done it in the past but couldn't find the file/recode. Packages like dart:http do not allow sending a body with a GET request. thanks for help julemand10

HTTP GET with request body RETROFIT

username I am using Retrofit to make api calls in my android application. I have to submit JSON @Body @GET("api/") void getData(@Body UserPostRequestBody request) I get the error message retrofit.RetrofitError: apiCall: Non-body HTTP method cannot contain @Bo

HTTP GET with request body RETROFIT

user2026760: I am using Retrofit to make api calls in my android application. I have to submit JSON @Body @GET("api/") void getData(@Body UserPostRequestBody request) I get the error message retrofit.RetrofitError: apiCall: Non-body HTTP method cannot contain

Sending HEAD http request with body results in net/http error

Rudziankoŭ: I want to raise this exception: // ErrBodyNotAllowed is returned by ResponseWriter.Write calls // when the HTTP method or response code does not permit a // body. ErrBodyNotAllowed = errors.New("http: request method or response status code does not

Sending HEAD http request with body results in net/http error

Rudziankoŭ: I want to raise this exception: // ErrBodyNotAllowed is returned by ResponseWriter.Write calls // when the HTTP method or response code does not permit a // body. ErrBodyNotAllowed = errors.New("http: request method or response status code does not

Sending HEAD http request with body results in net/http error

Rudziankoŭ: I want to raise this exception: // ErrBodyNotAllowed is returned by ResponseWriter.Write calls // when the HTTP method or response code does not permit a // body. ErrBodyNotAllowed = errors.New("http: request method or response status code does not

Error sending HTTP GET request with Volley in Android

AP01 I am using volley in an android application to make HTTP GET requests. I am getting the following error - (HTTPLog)-Static: isSBSettingEnabled false (HTTPLog)-Static: isSBSettingEnabled false BasicNetwork.performRequest: Unexpected response code 500 for D

Angular 7 not sending HTTP Post request data

Tanmay Vij I'm trying to send HTTP Post request to a REST API developed with ExpressJS. I am using the following service file to send requests using Angular's HttpClient: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/h

Angular 7 not sending HTTP Post request data

Tanmay Vij I'm trying to send HTTP Post request to a REST API developed with ExpressJS. I am using the following service file to send requests using Angular's HttpClient: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/h

Http POST request get headers and body

username I am currently using the code mentioned below to make a http post request and it only returns the body. I want body and title. How to get body and headers using file_get_content method or CURL? $sURL = "url"; $sPD = "data"; $aHTTP = array( 'http

How to get HTTP request body content in Laravel?

Beniz I am using the make API Laravel 5and I am using for testing PHPUnit. I need to test compatibility of old features, which is XML POST. As of now, my first test looks like this: public function testPostMessages() { $response = $this->call('POST', 'xml'