【发布时间】:2014-04-30 00:53:00
【问题描述】:
我对此深陷兔子洞。我正在创建一个简单的应用程序,它使用 SOLR 4 作为 NoSQL 数据存储和 AngularJS v1.2.2 作为界面。我已经从命令行加载了一堆文档,AngularJS 让搜索/查看这些文档变得非常容易。我想允许文档编辑,但不能让 POST 工作。 Chrome 控制台显示 400 错误,网络选项卡显示它在 OPTIONS 方法上失败。
网络标头:Request URL:http://localhost:8983/solr/mrm_assay/update
Request Method:OPTIONS
Status Code:400 Bad Request
Request Headers
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,es;q=0.6
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Cache-Control:no-cache
Connection:keep-alive
Host:localhost:8983
Origin:http://localhost:63342
Pragma:no-cache
Referer:http://localhost:63342/angular-solr2/app/index.html
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
Response Headers
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:origin, content-type, cache-control, accept, options
Access-Control-Allow-Methods:GET,POST,DELETE,PUT,HEAD,OPTIONS
Access-Control-Allow-Origin:http://localhost:63342
Access-Control-Max-Age:1800
Content-Type:application/xml; charset=UTF-8
Transfer-Encoding:chunked
架构概览:
SOLR 和 AngularJS 应用程序都在我的 Mac 上运行。
SOLR 使用默认的 Jetty 实例,Angular 应用程序在 WebStorm 的 IDE 的服务器内运行。 CORS 已启用,包括 GET、POST、DELETE、PUT、HEAD、OPTIONS。
更新在以下情况下起作用:
- 使用 SOLR 的仪表板
- 使用命令行(示例)
$ curl http://localhost:8983/solr/mrm_assay/update -H 'Content-type:application/json' -d '[ { "keep_in_assay" {"set" : "N", "detected_endog": "N", "problems_w_is": "removed b/c requires addition post-Oasis", "onc_std_set": "set1", "fraction_id": "7", "onclistgene": "UBL3", "geneid": "UBL3_IS6", "taxonid": "9606", "peptide": "SSNVPADMINLR", "degen_human": "1", "gene_degeneracy": "1", "percnt_id": "66.7", "uuid": "6d20eb03-d3ee-4eb2-bc16-27cfaabab989" } ]'
我的 Angular 控制器代码如下所示:assayControllers.controller('AssayUpdateController', ['$scope', '$http',
function($scope, $http){
$scope.processForm = function(){
console.log($scope.assay);
$http({
method:'POST',
url:'http://localhost:8983/solr/mrm_assay/update',
data : $scope.assay,
headers : {'Content-Type': 'application/json' }
})
.success(function(data, status, headers){
console.log(data.message);
})
.error(function(data, status, headers, config){
console.log(status);
});
};
}
]);
数据已从表单成功发送,正如我在控制台上看到的那样(尽管 JSON 对象未打包在数组中,这似乎是 SOLR 所期望的......我还尝试将 JSON 格式的数据推送到数组和 POST 但没有运气)
感谢您的帮助 - 即使只是为了指导我的故障排除!
【问题讨论】:
-
老实说,我不知道出了什么问题,这里的一切看起来都是正确的,但作为替代方案,您是否尝试过 $http.post("localhost:8983/solr/mrm_assay/update", $scope.assay) 忽略分号 SO 是无论出于何种原因添加它
-
是的,我也有,但也没有运气。