1

This is method that sends request to server:

public Get(body: IGetPassportInfoRequest): Observable<IGetPassportInfoResponse> {

    let httpHeaders = new HttpHeaders({
      'Content-Type' : 'application/json',
      'Cache-Control': 'no-cache'
    });

    let options = {
      headers: httpHeaders
    };

    return this.http.post('http://ip:9090/terminal/get', body, options)
      .catch(this.handleError);
  }

Where body is object:

 const data: IGetPassportInfoRequest = {
      doc_serie: this.step1.controls['passport_seria'].value,
      doc_number: this.step1.controls['passport_number'].value
    };

In chrome network I see:

enter image description here

4
  • Whats the response http code? Commented Aug 29, 2018 at 23:10
  • It sends OPTION request instead POST, why?: Request Method: OPTIONS Status Code: 405 Method Not Allowed Commented Aug 29, 2018 at 23:12
  • 1
    Have you enabled CORS on server? Commented Aug 29, 2018 at 23:13
  • 1
    cross domain requests are always pre-flighted by an OPTION request, you need to enable cors on your server side Commented Aug 29, 2018 at 23:14

1 Answer 1

1

What you got here is a CORS related error. The server that you are trying to send data to needs to:

  1. have appropriate CORS headers set
  2. allow an OPTION method to be handled (CORS requests are always pre-flighted with OPTION request)

Readmore: CORS

Sign up to request clarification or add additional context in comments.

6 Comments

Should I configure client or server?
Server. Depending on the type of software you are using there might be ready-made packages for your needs, or you'll need to manually set appropriate headers (usually you'll need allow-headers, allow-methods and allow-origin). As for the OPTION method, this can be the simplest route (i.e. return a blank page if the request method is OPTION).
Okay, then why does Postman work from local machine and gives correct response
Because it's not a cross-origin request (page requesting another page), but rather a direct request from your browser to the target (just as if you would open the page in brower)
Postman utilises your browser to send the request directly to target server. (so it's not a cross-origin request)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.