以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  axios请求问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=183347)

--  作者:qaz17909
--  发布时间:2022/11/2 11:42:00
--  axios请求问题
 狐表端开启8081端口服务,发现请求之后狐表端弹窗“未收到数据”,说明响应狐表端没有接受到参数,另外浏览器这边报错,没有返回成功数据,这个axios是不是写错了

HttpRequest中代码如下:
Select Case e.path
    Case "test"
        If e.Values.ContainsKey("firstName") Then
          MessageBox.Show(e.Values("firstName").ToString)
        Else
          MessageBox.Show("未收到数据!")
        End If
        e.WriteString("True")
end select

Vue中用axios请求
function signin() {
  axios({
    method: "get",
    url: "http://127.0.0.1:8081/test",
    data: {
      firstName: "Fred",
      lastName: "Flintstone",
    },
  })
  .then(function (response) {
    console.log(response);
  });
}
[此贴子已经被作者于2022/11/2 11:43:22编辑过]

--  作者:有点蓝
--  发布时间:2022/11/2 13:47:00
--  
https://www.axios-http.cn/docs/req_config
--  作者:qaz17909
--  发布时间:2022/11/2 14:05:00
--  
 把data参数改为params,服务器接收到了数据,但是返回的时候浏览器这边提示错误,这个应该怎么弄?
已拦截跨源请求:同源策略禁止读取位于 http://127.0.0.1:8081/test?firstName=Fred&lastName=Flintstone 的远程资源。(原因:CORS 头缺少 \'Access-Control-Allow-Origin\')。状态码:200。

--  作者:有点蓝
--  发布时间:2022/11/2 14:30:00
--  
跨域使用参考:http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=157245
--  作者:qaz17909
--  发布时间:2022/11/2 15:40:00
--  
 谢谢,可以了。另外还有个问题,我改用post请求的时候,这样写狐表端会报错,是为什么?
function signin() {
  axios({
    method: "post",
    url: "http://127.0.0.1:8081/test",
    data: {
      firstName: "Fred",
      lastName: "Flintstone",
    },
  })
  .then(function (response) {
    console.log(response);
  });
}

--  作者:有点蓝
--  发布时间:2022/11/2 16:08:00
--  
什么错?
--  作者:qaz17909
--  发布时间:2022/11/2 16:30:00
--  
 
调用的目标发生了异常。
未将对象引用设置到对象的实例。
--  作者:有点蓝
--  发布时间:2022/11/2 16:37:00
--  
调试看是哪一句代码出错
--  作者:qaz17909
--  发布时间:2022/11/2 16:58:00
--  
 用get写是可以的,用post写提示错误,这个地方e.WriteString(e.Values("firstName").ToString)错误。是不是post的写法不对
Select Case e.path
    Case "test"
        MessageBox.Show(123)  \'可弹窗
        e.WriteString(e.Values("firstName").ToString)  ‘错误
end select

Vue中用post请求
function signin() {
  axios({
    method: "post",
    url: "http://127.0.0.1:8081/test",
    data: {
      firstName: "Fred",
      lastName: "Flintstone",
    },
  })
  .then(function (response) {
    console.log(response);
  });
}
--  作者:有点蓝
--  发布时间:2022/11/2 17:14:00
--  
用开发者工具调试看前端提交的数据是怎么样的

服务端调试
MessageBox.Show(e.PlainText
MessageBox.Show(e.PostValues.Count)