当我过去将它作为一个应用程序运行时,我正在使用 fetch 从我的 react 组件调用 Web API,没有问题,但是当我运行应用程序 react 与 API 分开时,我收到 CORS 错误,我的 fetch 调用如下,
componentDidMount() {
console.log(clientConfiguration)
fetch(clientConfiguration['communitiesApi.local'])
.then((response) => {
return response.json();
})
.then(data => {
console.log(data);
let communitiesFromApi = data.map(community => { return { value: community, display: community } });
this.setState({ communities: [{ value: '', display: 'Select a Community...' }].concat(communitiesFromApi) });
}).catch(error => {
console.log(error);
});
};
Run Code Online (Sandbox Code Playgroud)
和我的 POST 调用也使用 Axios,如下所示。
handleDownload = (e) => {
e.preventDefault();
var formData = new FormData();
formData.append('communityname', this.state.selectedCommunity);
formData.append('files', JSON.stringify(this.state['checkedFiles']));
let …Run Code Online (Sandbox Code Playgroud) 您好,我有一个如下图所示的 Web api - 返回 HttpResponseMessage,我将 fileStream 作为其内容重新设置,当我尝试在控制台上检索或将其记录为 console.log(response.data) 时,它会显示一些其他信息,但是不是流信息或数组或任何此类内容。有人可以帮助我如何使用 React 读取或下载作为流或 FileStream 返回的文件。我没有使用 jQuery。请提供任何帮助,链接或类似的东西。我可以使用字节数组下载文件,但需要使用 FileStream 来实现,请问有什么帮助吗?
[EnableCors("AnotherPolicy")]
[HttpPost]
public HttpResponseMessage Post([FromForm] string communityName, [FromForm] string files) //byte[]
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var removedInvalidCharsFromFileName = removeInvalidCharsFromFileName(files);
var tFiles = removedInvalidCharsFromFileName.Split(',');
string rootPath = Configuration.GetValue<string>("ROOT_PATH");
string communityPath = rootPath + "\\" + communityName;
byte[] theZipFile = null;
FileStreamResult fileStreamResult = null;
using (MemoryStream zipStream = new MemoryStream())
{
using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
{
foreach (string …Run Code Online (Sandbox Code Playgroud) 我正在尝试插值
var sample = "test";
var result = 'this is just a ${sample}';
alert(result);
Run Code Online (Sandbox Code Playgroud)
它没有用,只是在发出警报,这只是$ {sample},有人可以在这方面帮助我吗?谢谢