zoukankan      html  css  js  c++  java
  • spring 的自建request请求

    public String myRequest() throws IOException, URISyntaxException{
            
            String url="http://localhost:8080/testspring/myResponse";
            ClientHttpRequest request = new SimpleClientHttpRequestFactory().createRequest(new URI(url), HttpMethod.POST);
            request.getHeaders().set("Content-Type", "application/json;charset=gbk");
            String json = "{\"name\":\"monkey\",\"password\":\"1234\"}";
            request.getBody().write(json.getBytes("gbk"));
            ClientHttpResponse response = request.execute();
            InputStream is = response.getBody();
            byte[] b = new byte[(int) response.getHeaders().getContentLength()];
            is.read(b);
            String s = new String(b,"gbk");
            System.out.println(s);
            
            return null;

    }

    这里的uri必须要用绝对路径。

    媒体格式网上自行百度

    public void myResponse(HttpServletRequest request,HttpServletResponse response) throws IOException{
            InputStream is = request.getInputStream();
            byte[] bytes = new byte[request.getContentLength()];
            is.read(bytes);
            String string = new String(bytes,request.getCharacterEncoding());
            System.out.println(string);
            response.getWriter().write("success");
            
        }

  • 相关阅读:
    端口号被占用怎么办
    cxgrid动态显示行号
    SQL事件探查器后无法暂停及停止
    互联网电视音视频编码规范
    视频服务之ffmpeg部署
    如何远程连接AWSEC2实例
    测试kernel.pid_max值
    ffmpeg常用命令
    视频服务之(直播&点播)
    视频服务之在线教育系统BigBlueButton
  • 原文地址:https://www.cnblogs.com/monkeydai/p/4337647.html
Copyright © 2011-2022 走看看