首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >POST cURL转到cURL

POST cURL转到cURL
EN

Stack Overflow用户
提问于 2022-10-22 21:31:33
回答 1查看 43关注 0票数 0

我有一个应用程序,它是使用回弹在后端和反应在前面。在应用程序中,一切都是正确的。我只是想知道,当cURL被移过铬和边缘,然后在邮递员中使用时,它就变成了请求。我不明白它为什么会收到请求。(共享图像中的步骤3)

重复这个场景。我总结了我的密码。

后端:

代码语言:javascript
复制
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
public class TestApi {
  @PostMapping("/uploadFile")
  public void uploadFile(@RequestPart MultipartFile multipartFile) {
      System.out.println(multipartFile.getName());
  }
}

用于前端:

代码语言:javascript
复制
import FormControl from '@mui/material/FormControl';  
import CssBaseline from '@mui/material/CssBaseline'; 
import Container from '@mui/material/Container';    
import Grid from '@mui/material/Grid';  
import React, { useState } from 'react';
import axios from 'axios';

function ManagementAuth() {  
   const [imageFile, setImageFile] = useState([]);    

   const fileSelectedHandler = (event) => {
      setImageFile(event.target.files[0]);
   }; 

const fileUploadHandler = (event) => {
    const fd = new FormData();
    fd.append('multipartFile', imageFile, imageFile.name);
    axios.post('http://localhost:8080/uploadFile', fd)
    .then(res => {
        console.log(res);
    });
}; 

return (
    <React.Fragment>
    <CssBaseline />
        <Container maxWidth="sm">
            <Grid
                container
                spacing={0}
                direction="column"
                alignItems="center"
                justifyContent="center"
                style={{ minHeight: '80vh' }}
                >        
                <FormControl sx={{ m: 1, width: '35ch' }} variant="standard"> 
                    <input type="file" onChange={fileSelectedHandler}/>
                    <button onClick={fileUploadHandler}>Upload</button>
                </FormControl>     
            </Grid> 
        </Container>
    </React.Fragment>
  );
}

export default ManagementAuth;

在运行了两个应用程序之后,

第一步

第二步

第三步

EN

回答 1

Stack Overflow用户

发布于 2022-10-22 21:38:41

会把这作为一种评论,但我还不能评论。一个快速的搜索打开了这个https://support.postman.com/hc/en-us/articles/211913929-My-request-is-redirected-to-a-GET-request#:~:text=To%20do%20this%2C%20open%20the,Follow%20original%20HTTP%20method%20option

您正在经历以下问题之一

  • 所有的请求都是以GET请求的形式发送的,不管您选择哪种HTTP方法,都是
  • 当HTTP和HTTPS之间存在重定向时,您选择的原始HTTP请求方法不会被保留。

期待什么

邮递员会自动重定向返回3xx响应的请求。注意:要检查3xx响应,请使用Postman控制台并验证它是否显示了3xx响应。如果是,则表示重定向。如果没有,请提交支持请求(见下文)。

如何解除对自己的束缚

  • 禁用3xx响应的自动重定向。为此,请打开请求的“设置”选项卡,然后关闭“自动跟随重定向”选项。
  • 强制您的请求遵循原始HTTP方法。为此,请打开请求的Settings选项卡,然后切换以下原始HTTP方法选项。
  • 如果您的API服务提供者使用Nginx作为web服务器,则在请求URL上添加一个尾斜杠(/)。
  • 如果这些选项都没有帮助,请联系您的API服务提供商以获得帮助。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74167232

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档