postman js 跨域请求原理是啥?
1
fengliu222 2015-09-10 15:53:47 +08:00
Chrome 插件内木有同源策略的限制,所以不跨域。
|
2
yunfeifan 2015-09-10 16:07:03 +08:00
@fengliu222 有权限限制的,不过可以申请到跨域(跨指定域名或所有)
|
4
yunfeifan 2015-09-10 16:18:17 +08:00
@hobbyliu manifest 文件中
"permissions": [ "http://www.google.com/" ], 跨域允许设置可以使用完整域名, 例如: "http://www.google.com/" "http://www.gmail.com/" 或者使用模式匹配, 例如: "http://*.google.com/" "http://*/" 模式匹配"http://*/" 表示可以发起到所有域的 HTTP 请求. 注意在这里, 模式匹配有点像内容脚本匹配, 但是这里的任何域名后的路径信息都被忽略 |
5
hobbyliu OP @yunfeifan postman 插件里面的一个方法, 没法发现请求域的设置呢?
`` //Send the current request send:function (responseRawDataType ) { pm.request.prepareForSending (); if (pm.request.url === "") { return; } var originalUrl = $('#url').val (); //Store this for saving the request var url = pm.request.encodeUrl (pm.request.url ); var method = pm.request.method.toUpperCase (); var originalData = pm.request.body.getData (true ); //Start setting up XHR var xhr = new XMLHttpRequest (); xhr.open (method, url, true ); //Open the XHR request. Will be sent later xhr.onreadystatechange = function (event ) { pm.request.response.load (event.target ); }; //Response raw data type is used for fetching binary responses while generating PDFs if (!responseRawDataType ) { responseRawDataType = "text"; } xhr.responseType = responseRawDataType; var headers = pm.request.getXhrHeaders (headers ); for (var i = 0; i < headers.length; i++) { xhr.setRequestHeader (headers[i].name, headers[i].value ); } // Prepare body if (pm.request.isMethodWithBody (method )) { var body = pm.request.getRequestBodyToBeSent (); if (body === false ) { xhr.send (); } else { xhr.send (body ); } } else { xhr.send (); } pm.request.response.iframeRefreshedRecently = false; pm.request.xhr = xhr; //Save the request if (pm.settings.get ("autoSaveRequest")) { pm.history.addRequest (originalUrl, method, pm.request.getPackedHeaders (), originalData, pm.request.dataMode ); } //Show the final UI pm.request.updateUiPostSending (); }, `` |
7
fengliu222 2015-09-11 00:08:44 +08:00
@yunfeifan 噗。。。你说的没错,我忘记了。
|