我想使用rest api获取数据。我正在通过我的休息api,但显示错误
Function Import_Match_Report()
'On Error Resume Next
'Get folder & file list
Dim Source_folder As String
Source_folder = Get_Folder()
Dim FSO As New FileSystemObject
Set flist = FSO.GetFolder(Source_folder).Files
M = InputBox("update period (01-12)")
'delete prior data
CurrentDb().Execute ("delete * from [Matching Report] where period=" & M)
'Process each file
SQL = "INSERT INTO [Matching Report] ([period],[account], [reporting unit],[reporting unit title],[amount],[offset unit],[offset unit title],[offset],[variance]) "
For Each file In flist
If (Len(Dir(Source_folder & "\" & file.Name)) = 0) Then GoTo NextFile
If file.Size = 0 Then GoTo NextFile
Source = file.Name
period = Mid(Source, 7, 2)
If period <> M Then GoTo NextFile
account = Mid(Source, InStr(Source, ".") - 9, 9)
CurrentDb().Execute ("delete * from [matching report temp]")
DoCmd.TransferText acImportDelim, "match_spec", "matching report temp", Source_folder & "\" & file.Name
SQL2 = SQL & " select " & period & ",'" & account & "', F1, F2, F3, F4, F5, F6, F7 from [matching report temp]"
CurrentDb.Execute SQL2
table = Left(Source, InStr(Source, ".") - 1)
If table_exist(table & "_ImportErrors") Then DoCmd.DeleteObject acTable, table & "_ImportErrors"
NextFile: Next file
MsgBox ("data import completed")
End Function
Public Function Get_Folder()
'Create a FileDialog object as a Folder Picker dialog box.
Const msoFileDialogFolderPicker = 4
Const msoFileDialogFilePicker = 3
Const msoFileDialogViewDetails = 2
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.AllowMultiSelect = False
fd.ButtonName = "Select"
fd.InitialView = msoFileDialogViewDetails
fd.Title = "Select Folder"
fd.InitialFileName = "MyDocuments\"
fd.Filters.Clear
'Show the dialog box and get the file name
If fd.Show = -1 Then
Get_Folder = fd.SelectedItems(1)
Else
Get_Folder = "MyDocuments\"
End If
Set fd = Nothing
End Function
任何人帮我解决上述错误?
答案 0 :(得分:1)
我认为这是跨域问题 如果rest服务器和角度服务器是同一台服务器。 试试以下。
this.http.get('/JsonServices.php?action=getempdata')
如果“ip”是外部服务器。 服务器需要回复CORS的响应头
我不知道您的服务器代码。但修复的图像在下面。
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
w.Header().Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")