文档章节

curl 测试cros请求

O0lele0O
 O0lele0O
发布于 2016/10/24 15:08
字数 414
阅读 36
收藏 0

Sending a regular CORS request using cUrl:

curl -H "Origin: http://example.com" --verbose
https://www.googleapis.com/discovery/v1/apis?fields= The -H "Origin: http://example.com" flag is the third party domain making the request. Substitute in whatever your domain is.

The --verbose flag prints out the entire response so you can see the request and response headers.

The url I'm using above is a sample request to a Google API that supports CORS, but you can substitute in whatever url you are testing.

The response should include the Access-Control-Allow-Origin header.

Sending a preflight request using cUrl:

curl -H "Origin: http://example.com"
-H "Access-Control-Request-Method: POST"
-H "Access-Control-Request-Headers: X-Requested-With"
-X OPTIONS --verbose
https://www.googleapis.com/discovery/v1/apis?fields= This looks similar to the regular CORS request with a few additions:

The -H flags send additional preflight request headers to the server

The -X OPTIONS flag indicates that this is an HTTP OPTIONS request.

If the preflight request is successful, the response should include the Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers response headers. If the preflight request was not successful, these headers shouldn't appear, or the HTTP response won't be 200.

You can also specify additional headers, such as User-Agent, by using the -H flag.

shareimprove this answer edited Aug 29 '12 at 14:01 answered Aug 29 '12 at 13:42

monsur 19.6k66884 1 that page does not seem to return any CORS headers, is that correct? – Janus Troelsen Feb 24 '13 at 20:01

In order to view the actual headers, you need to add the --verbose option, as mentioned above. – monsur Feb 25 '13 at 14:24

Hmm, that may be a bug. Can you try the same request to the following url: server.cors-api.appspot.com/… – monsur Feb 25 '13 at 15:41

--verbose wasn't displaying headers for me either. I replaced it with "--trace-ascii -" – Bryan Larsen Sep 30 '13 at 15:00 2 or --head: curl -H "Origin: http://example.com" --head https://www.googleapis.com/discovery/v1/apis?fields= – John Bachir Apr 6 '14 at 5:30 1 Use --include to see the headers. – Mika Tuupola Feb 18 at 16:18

In the case of S3, the according headers are only added if the proper method is given, you can do so by using curl -H "Access-Control-Request-Method: GET" -H "Origin: http://example.com" -I https://s3.amazonaws.com/your-bucket/file. – Joscha Mar 2 at 2:13

本文转载自:

共有 人打赏支持
O0lele0O
粉丝 2
博文 15
码字总数 25
作品 0
佳木斯
Spring跨域问题

spingMVC 3.X跨域 关于跨域问题,主要用的比较多的是cros跨域。 详细介绍请看https://developer.mozilla.org/zh-CN/docs/Web/HTTP/AccesscontrolCORS 但是,在springmvc+angularjs下支持跨域...

刘引惟
2016/11/17
26
0
spring mvc+Ajax跨域请求-CORS方式

关于跨域问题,主要用的比较多的是cros跨域和JSONP跨域,JSONP跨域我已经在另外一篇博客中写了,这里主要说的是CORS方式的跨域。 CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin re...

别寒
2016/11/02
174
0
Linux安装、使用curl进行Get、Post接口调试

一、linux中如何安装Curl,步骤如下: 1.下载 wget http://curl.haxx.se/download/curl-7.38.0.tar.gz 注意: 如果命令执行失败,请使用浏览器打开链接进行下载,然后在Linux上使用“rz”命令...

mamadu
2017/10/30
0
0
使用curl 命令模拟POST/GET请求

curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载。curl支持包括HTTP、HTTPS、ftp等众多协议,还支持POST、cookies、认证、从指定偏移处下载部分文件、用户代...

zhongbeida_xue
05/25
0
0
cURL使用心得

cURL是我在Linux上经常用的一个小工具,我理解它是一个“客户端”。今天记录一下我的使用心得。达人请忽略。 cURL是一个利用URL语法在命令行方式下工作的文件传输工具。它支持很多协议:FTP...

鉴客
2010/08/24
1K
2

没有更多内容

加载失败,请刷新页面

加载更多

创建第一个react项目

sudo npm i -g create-react-app@1.5.2 create-react-app react-app cd react-apprm -rf package-lock.jsonrm -rf node_modules #主要是为了避免报错npm installnpm start......

lilugirl
今天
3
0
在浏览器中进行深度学习:TensorFlow.js (八)生成对抗网络 (GAN)

Generative Adversarial Network 是深度学习中非常有趣的一种方法。GAN最早源自Ian Goodfellow的这篇论文。LeCun对GAN给出了极高的评价: “There are many interesting recent development...

naughty
今天
0
0
搬瓦工镜像站bwh1.net被DNS污染,国内打不开搬瓦工官网

今天下午(2018年10月17日),继搬瓦工主域名bandwagonhost.com被污染后,这个国内的镜像地址bwh1.net也被墙了。那么目前应该怎么访问搬瓦工官网呢? 消息来源:搬瓦工优惠网->搬瓦工镜像站b...

flyzy2005
今天
6
0
SpringBoot自动配置

本篇介绍下,如何通过springboot的自动配置,将公司项目内的依赖jar,不需要扫描路径,依赖jar的情况下,就能将jar内配置了@configuration注解的类,创建到IOC里面 介绍下开发环境 JDK版本1.8 spr...

贺小五
今天
5
0
命令行新建Maven多项目

参考地址 # DgroupId 可以理解为包名# DartifactId 可以理解为项目名mvn archetype:generate -DgroupId=cn.modfun -DartifactId=scaffold -DarchetypeArtifactId=maven-archetype-quickst......

阿白
今天
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部