-1

Not able to figure out why the response is coming as null.

When tested with mock data, it works perfectly fine but when I'm trying to hit our API which is hosted in AWS EC2, the response comes as null and the error message comes in the console as follows

Cross-Origin Read Blocking (CORB) blocked cross-origin response http://example.com/search/api?limit=10&offset=10 with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

However, I verified in the browser's Network tab, It shows 200 OK. Also, I verified this API call with Postman client and the data is being shown.

I tried various ways of disabling the web security option in Chrome browser but no luck. I also have CORS extension in my Chrome browser.

Could anyone please guide what I'm doing wrong here.

Service

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class SearchService {

  searchUrl = 'http://example.com/search/api?limit=10&offset=10'
  mockDataUrl = 'https://jsonplaceholder.typicode.com/posts';

  constructor(private httpClient: HttpClient) { }

  getMockData() {
    return this.httpClient.get(this.mockDataUrl);
  }

  getSearchData() {
    return this.httpClient.get(this.searchUrl);
  }

}

Component

export class AppComponent implements OnInit {

  ngOnInit() {
    this.searchService.getSearchData().subscribe(
      (response) => { console.log(response); }
    );
  }
}
coderpc
  • 4,119
  • 6
  • 51
  • 93
  • For resolving CORS, you need to allow your origin in on the server. check `Access-Control-Allow-Origin` on the server or you can check this in response headers of inflight call. – Anand G Nov 06 '19 at 21:43
  • I'm able to get the data if I try to hit the API using Postman or any browser. The problem persists when I'm trying to hit that API through my Ionic App. @AnandG – coderpc Nov 06 '19 at 22:09

1 Answers1

-1

This is the only solution that worked for me.

Once I installed this extension and enabled it, I was able to see the response.

coderpc
  • 4,119
  • 6
  • 51
  • 93