Fiddler工具响应post的请求 request body的填写规则

Fiddler 的post请求有两种格式:

第一种:name1=valule1&name2=value2...  具体写法如图所示:



第二种:json数据格式   {"参数名":"参数值","参数名":"参数值",...}   具体写法如图所示:



代码如下:

package com.cn.webservice.controller;

import java.io.BufferedReader;
import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.webservice.pojo.User;
import com.cn.webservice.service.ILoginService;

@Controller
@RequestMapping("/login")
public class LoginController {

    @Resource
    private ILoginService loginService;

    @RequestMapping("/login1")
    @ResponseBody
    public String login1(HttpServletRequest request) throws IOException {

        System.out.println("this is  LoginController");
        String userName = request.getParameter("userName");
        String passWord = request.getParameter("passWord");
        System.out.println(userName + "  --  " + passWord);
        int key = loginService.login(userName, passWord);

        if (key >= 1) {
            return "success";
        } else {
            return "fail";
        }

    }

    @RequestMapping("/login2")
    @ResponseBody
    public String login2(HttpServletRequest request) throws IOException {

        String jsonString = getBodyString(request.getReader());

        JSONObject jbJsonObject = new JSONObject().fromObject(jsonString);

        User user = (User) JSONObject.toBean(jbJsonObject, User.class);
        System.out.println(jbJsonObject);
        System.out.println("id:" + user.getId());
        System.out.println("name:" + user.getName());

        return null;

    }

    @RequestMapping("/login3")
    @ResponseBody
    public String login3(User user) throws IOException {

        System.out.println("---------------");
        System.out.println(user.getUserName());
        System.out.println(user.getPassWord());
        System.out.println("---------------");

        if (true) {
            return "success";
        } else {
            return "fail";
        }

    }

    public String getBodyString(BufferedReader br) {
        String inputLine;
        String str = "";
        try {
            while ((inputLine = br.readLine()) != null) {
                str += inputLine;
            }
            br.close();
        } catch (IOException e) {
            System.out.println("IOException: " + e);
        }
        return str;
    }

}


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值