我目前正在开发一个基于服务的系统,并且对http请求有一些问题(似乎是CORS的一个问题 - 跨源资源共享)。
我发送请求的API是用PHP编写的,使用Slim框架,我实际上是使用以下代码启用CROS:
$app->add(function ($req, $res, $next) {
$response = $next($req, $res);
return $response
->withHeader('Access-Control-Allow-Origin', '')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
});
但是当我从前端发送请求时(用Angular编写):
this.http.get(this.base_url + "api/users/")
.subscribe(
(data) => {
console.log(data);
},
(error) => {
console.log(error);
});
我收到以下错误:
name:"HttpErrorResponse"
message:"Http failure response for (unknown url): 0 Unknown Error"
这两个项目在Docker中运行,如果它添加了信息。
有没有人知道问题出在哪里?
提前谢谢!
答案 0 :(得分:0)
这种情况通常是500代码内部服务器错误。
类似的原因:
final LinearLayout singleMonthLayout = (LinearLayout) inflater.inflate(R.layout.calendar_month_view, null);
final GridView gridview = (GridView) singleMonthLayout.findViewById(R.id.gridview);
final CalendarAdapter adapCal = new CalendarAdapter(getContext());
gridview.setAdapter(adapCal); // the adapter for the gridview
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent, View view, final int position, long id) {
if (parent instanceof GridView) {
int dayOfMonth = adapCal.getDayOfMonth(position);
System.out.println("gridView -> click "+ dayOfMonth +"!");
Log.d("-> StackTrace", Log.getStackTraceString(new Exception()));
// do stuff;
}
monthListView.addHeaderView(singleMonthLayout, null, false);
monthListView.setAdapter(viewAdapter); // the adapter for the listview