Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.ajax({
- type: "POST",
- dataType: 'text',
- url: api,
- username: 'user',
- password: 'pass',
- crossDomain : true,
- xhrFields: {
- withCredentials: true
- }
- })
- .done(function( data ) {
- console.log("done");
- })
- .fail( function(xhr, textStatus, errorThrown) {
- alert(xhr.responseText);
- alert(textStatus);
- });
- chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
- $.ajax({
- type: "POST",
- dataType: 'jsonp',
- ...... etc ......
- <?php header('Access-Control-Allow-Origin: *'); ?>
- // The following property can be used to configure cross-origin resource sharing
- // in the HTTP nodes.
- // See https://github.com/troygoode/node-cors#configuration-options for
- // details on its contents. The following is a basic permissive set of options:
- httpNodeCors: {
- origin: "*",
- methods: "GET,PUT,POST,DELETE"
- },
- app.use(function(req, res, next) {
- res.header("Access-Control-Allow-Origin", "*");
- res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- next();
- });
- <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Origin" value="*" />
- </customHeaders>
- </httpProtocol>
- $.ajax({
- url: 'http://mysite.microsoft.sample.xyz.com/api/mycall',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- type: "POST", /* or type:"GET" or type:"PUT" */
- dataType: "json",
- data: {
- },
- success: function (result) {
- console.log(result);
- },
- error: function () {
- console.log("error");
- }
- });
- System.Net.WebClient wc = new System.Net.WebClient();
- string str = wc.DownloadString("http://mysite.microsoft.sample.xyz.com/api/mycall");
- <cffunction name="optionsMethod" access="remote" output="false" returntype="any" httpmethod="OPTIONS" description="Method to respond to AngularJS trial call">
- <cfheader name="Access-Control-Allow-Headers" value="Content-Type,x-requested-with,Authorization,Access-Control-Allow-Origin">
- <cfheader name="Access-Control-Allow-Methods" value="GET,OPTIONS">
- <cfheader name="Access-Control-Allow-Origin" value="*">
- <cfheader name="Access-Control-Max-Age" value="360">
- </cffunction>
- Spark.get("/someRestCallToSpark", (req, res) -> {
- res.header("Access-Control-Allow-Origin", "*"); //important, otherwise its not working
- return "some text";
- });
- Ext.Ajax.request({
- url: "http://localhost:4567/someRestCallToSpark",
- useDefaultXhrHeader: false, //important, otherwise its not working
- success: function(response, opts) {console.log("success")},
- failure: function(response, opts) {console.log("failure")}
- });
- var yql_url = 'https://query.yahooapis.com/v1/public/yql';
- var url = 'your api url';
- $.ajax({
- 'url': yql_url,
- 'data': {
- 'q': 'SELECT * FROM json WHERE url="'+url+'"',
- 'format': 'json',
- 'jsonCompat': 'new',
- },
- 'dataType': 'jsonp',
- 'success': function(response) {
- console.log(response);
- },
- });
- using (DBContext db = new DBContext())
- {
- return db.Customers.Select(x => new
- {
- Name = x.Name,
- CustomerId = x.CustomerId,
- });
- }
- using (DBContext db = new DBContext())
- {
- return db.Customers.Select(x => new
- {
- Name = x.Name,
- CustomerId = x.CustomerId,
- }).ToList();
- }
- @GET
- @Path("{id}")
- public Response getEventData(@PathParam("id") String id) throws FileNotFoundException {
- InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/eventdata/" + id + ".json");
- JsonReader jsonReader = Json.createReader(inputStream);
- return Response.ok(jsonReader.readObject()).header("Access-Control-Allow-Origin", "*").build();
- }
- <IfModule mod_headers.c>
- <FilesMatch ".(ttf|ttc|otf|eot|woff|woff2|font.css|css)$">
- Header set Access-Control-Allow-Origin "*"
- </FilesMatch>
- </IfModule>
- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '…' is therefore not allowed access
- <?php header('Access-Control-Allow-Origin: *'); ?>
- $.ajax({
- url: yourserver.com/controller/proxy.php,
- async: false,
- type: "POST",
- dataType: "json",
- data: data,
- success: function (result) {
- JSON.parse(result);
- },
- error: function (xhr, ajaxOptions, thrownError) {
- console.log(xhr);
- }
- });
- if (isset($_POST)) {
- $apiKey = $_POST['apiKey'];
- $cid = $_POST['cid'];
- $minorRev = 99;
- $url = 'http://api.ean.com/ean-services/rs/hotel/v3/list?' . 'cid='. $cid . '&' . 'minorRev=' . $minorRev . '&' . 'apiKey=' . $apiKey;
- echo json_encode(file_get_contents($url));
- }
- echo json_encode(file_get_contents($url));
- Access-Control-Allow-Origin: http://foo.example
- Access-Control-Allow-Origin: *
- func main() { // API Server Code
- router := mux.NewRouter()
- // API route is /people,
- //Methods("GET", "OPTIONS") means it support GET, OPTIONS
- router.HandleFunc("/people", GetPeople).Methods("GET", "OPTIONS")
- log.Fatal(http.ListenAndServe(":9091", router))
- }
- // Method of '/people' route
- func GetPeople(w http.ResponseWriter, r *http.Request) {
- // Allow CORS by setting * in sever response
- w.Header().Set("Access-Control-Allow-Origin", "*")
- w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
- json.NewEncoder(w).Encode("OKOK")
- }
- function GetPeople() {
- try {
- var xhttp = new XMLHttpRequest();
- xhttp.open("GET", "http://localhost:9091/people", false);
- xhttp.setRequestHeader("Content-type", "text/html");
- xhttp.send();
- var response = JSON.parse(xhttp.response);
- alert(xhttp.response);
- }
- catch (error) {
- alert(error.message);
- }
- }
- catta('./data/simple.json').then(function (res) {
- console.log(res);
- });
- window.handleData = function(data) {
- console.log(data)
- };
- var script = document.createElement('script');
- script.setAttribute('src','https://some.api/without/cors/headers.com&callback=handleData');
- document.body.appendChild(script);
- <system.webServer>
- <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Origin" value="*" />
- <add name="Access-Control-Allow-Headers" value="Content-Type" />
- <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
- </customHeaders>
- </httpProtocol>
- </system.webServer>
- after_action :cors_set_access_control_headers
- def cors_set_access_control_headers
- headers['Access-Control-Allow-Origin'] = '*'
- headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
- headers['Access-Control-Allow-Headers'] = '*'
- end
- var rp = require('request-promise');
- var express = require('express'),
- app = express(),
- port = process.env.PORT || 3000;
- var options = {
- method: 'POST',
- uri: 'http://api.posttestserver.com/post',
- body: {
- some: 'payload'
- },
- json: true // Automatically stringifies the body to JSON
- };
- app.get('/', function (req, res) {
- rp(options)
- .then(function (parsedBody) {
- res.send(parsedBody)
- })
- .catch(function (err) {
- res.send(err)
- });
- });
- app.listen(port);
- axios.get("http://localhost:3000/").then((res)=>{
- console.log('================res====================');
- console.log(res);
- console.log('====================================');
- })
- opera --user-data-dir="~/Downloads/opera-session" --disable-web-security
Add Comment
Please, Sign In to add comment