question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

superagent always send data by OPTIONS method

See original GitHub issue
request
    .get(url)
    .end(function (err, res) {
        if (err) {
            console.log(url);
            console.log(err);
        } else {
            var data = res.body;
            callback(data, ctx);
        }
    });

I always get this response

Request Method:OPTIONS Status Code:405 METHOD NOT ALLOWED

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kornelskicommented, Nov 2, 2016

If you’re making request in the browser, the OPTIONS request (called preflight) is done by the browser, not by superagent. Superagent can’t do anything about it. Superagent can’t even detect when it’s happening, and that’s by design. See CORS:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

When you make a request to another origin (URL with a different host/port/protocol than the page, i.e. generally absolute URL instead of a relative path) you have to deal with CORS. This is mandatory for security, and you’ll most likely need to implement appropriate response on the server. There are exceptions for “simple” GET requests, but POSTing or GET with custom HTTP headers will make browser send another OPTIONS request first to check if these extra features are allowed by the server.

0reactions
neekeycommented, Nov 2, 2016

sorry, I doubled checked, not an issue with superagent, just the browser’s CORS strategy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

superagent always send data by OPTIONS method · Issue #692
When you make a request to another origin (URL with a different host/port/protocol than the page, i.e. generally absolute URL instead of a ......
Read more >
Using .send() with SuperAgent request.post() makes General ...
But when I changed .query() to .send() to pass the input values as form-data instead of query-string-parameters, the Request Method was changed ...
Read more >
A Complete Guide to Making HTTP Requests in Node.js
This article will discuss more on HTTP, HTTP requests, ways to make this requests in Node and how we can handle errors.
Read more >
node_modulesold/superagent/docs - GitLab
To send the data as application/x-www-form-urlencoded simply invoke .type() with "form", where the default is "json". This request will POST the body "name= ......
Read more >
Javascript – How to send a request with superagent that uses the ...
I am trying to make a request against a php server that is constructing the url like this: website.com/?q=help&q=moreHelp&q=evenMoreHelp.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found