post请求返回400错误但是postman却调用成功

HTTP POST请求400错误排查与解决方案 HTTP 400 Bad Request错误是客户端请求存在语法问题时服务器返回的状态码。理解HTTP协议和RESTful API设计原则是排查这类错误的基础。从技术实现看,400错误通常源于请求头配置不当、请求体格式错误或参数验证失败,这些问题直接影响API调用的成功率。在实际开发中,合理使用Postman、curl等调试工具能快速定位问题,而完善的客户端校验和错误处理机制则是预防400错误的关键。特别是在JSON数据交互和HTTPS通信场景下,Content-Type设置和TLS配置成为高频出错点。掌握 阅读详情

post请求返回400错误但是postman却调用成功

遇到一个很奇怪的问题,做一个http调用其他系统api的功能,代码写完后在本地测试一切正常,但是部署到服务器后post请求全部都400错误了
怀疑是参数格式错了,然后在日志里面把URL和参数复制出来在postman中调用测试,发现居然成功调用
然后以为请求工具类有问题,又在本地跑起来一遍,发现又是一切正常,那么代码应该没有问题才对
因为postman成功了所以地址和参数应该也没有问题,那么测试后也发现参数只有格式错了才会返回400错误
那么也就是说我的参数在发送之后被改变了格式,(一番折腾后)最后讲视线放在了Tomcat上面,查找资料的过程中得知Tomcat的属性里面有一个MaxPostSize属性,这个属性设置为-1就可以了,他的作用就是限制post请求的参数大小,-1是不限制大小,如果没有自己添加一下
在conf/server.xml 文件中,在 标签中设置 maxPostSize="-1"
后来发现上面那个方法是错误的
正确的是换一个http工具类,用HTTPclient这种方式,代码如下,token可以自己换掉


import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class HttpUtil {


    private static final Logger log = LoggerFactory.getLogger(HttpUtil.class);

        /**
         * 原生字符串发送get请求
         *
         * @param url
         * @return
         * @throws IOException
         * @throws
         */
        public static String doGet(String url, String token) {
            log.info("url:"+url);
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpGet httpGet = new HttpGet(url);
            httpGet.setHeader("Content-type", "application/json");
            httpGet.setHeader("DataEncoding", "UTF-8");
            httpGet.setHeader("token", token);
            RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
            httpGet.setConfig(requestConfig);

            CloseableHttpResponse httpResponse = null;
            try {

                httpResponse = httpClient.execute(httpGet);
                HttpEntity entity = httpResponse.getEntity();
                String result = EntityUtils.toString(entity);
                log.info("result:"+result);
                return result;
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                log.info("ClientProtocolException:"+e.getMessage(),e);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.info("IOException:"+e.getMessage(),e);
            } finally {
                if (httpResponse != null) {
                    try {
                        httpResponse.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        log.info("IOException:"+e.getMessage(),e);
                    }
                }
                if (null != httpClient) {
                    try {
                        httpClient.close();
                    } catch (IOException e) {
                        log.info("IOException:"+e.getMessage(),e);
                    }
                }
            }
            return null;
        }

        /**
         * 原生字符串发送post请求
         *
         * @param url
         * @param jsonStr
         * @return
         * @throws IOException
         */
        public static String doPost(String url, String token, String jsonStr) {
            log.info("url:"+url);
            log.info("params:"+jsonStr);
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost(url);
            RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
            httpPost.setConfig(requestConfig);
            // 首先Header部分需要设定字符集为:uft-8
            httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
            // 此处也需要设定
            httpPost.setHeader("Accept", "application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            httpPost.setHeader("Accept-Encoding", "gzip, deflate");
            httpPost.setHeader("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
            httpPost.setHeader("Connection", "keep-alive");
            httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36");
            httpPost.setHeader("token", token);

            CloseableHttpResponse httpResponse = null;
            try {
                httpPost.setEntity(new StringEntity(jsonStr,"utf-8"));
                httpResponse = httpClient.execute(httpPost);
                HttpEntity entity = httpResponse.getEntity();
                String result = EntityUtils.toString(entity);
                log.info("result:"+result);
                return result;
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                log.info("ClientProtocolException:"+e.getMessage(),e);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.info("IOException:"+e.getMessage(),e);
            } finally {
                if (httpResponse != null) {
                    try {
                        httpResponse.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        log.info("IOException:"+e.getMessage(),e);
                    }
                }
                if (null != httpClient) {
                    try {
                        httpClient.close();
                    } catch (IOException e) {
                        log.info("IOException:"+e.getMessage(),e);
                    }
                }
            }
            return null;
        }

        /**
         * 原生字符串发送put请求
         *
         * @param url
         * @param token
         * @param jsonStr
         * @return
         * @throws ClientProtocolException
         * @throws IOException
         */
        public static String doPut(String url, String token, String jsonStr) {
            log.info("url:"+url);
            log.info("params:"+jsonStr);
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPut httpPut = new HttpPut(url);
            RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
            httpPut.setConfig(requestConfig);
            // 首先Header部分需要设定字符集为:uft-8
            httpPut.addHeader("Content-Type", "application/json;charset=utf-8");
            // 此处也需要设定
            httpPut.setHeader("Accept", "application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            httpPut.setHeader("Accept-Encoding", "gzip, deflate");
            httpPut.setHeader("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
            httpPut.setHeader("Connection", "keep-alive");
            httpPut.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36");
            httpPut.setHeader("token", token);

            CloseableHttpResponse httpResponse = null;
            try {
                httpPut.setEntity(new StringEntity(jsonStr,"utf-8"));
                httpResponse = httpClient.execute(httpPut);
                HttpEntity entity = httpResponse.getEntity();
                String result = EntityUtils.toString(entity);
                log.info("result:"+result);
                return result;
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                log.info("ClientProtocolException:"+e.getMessage(),e);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.info("IOException:"+e.getMessage(),e);
            } finally {
                if (httpResponse != null) {
                    try {
                        httpResponse.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        log.info("IOException:"+e.getMessage(),e);
                    }
                }
                if (null != httpClient) {
                    try {
                        httpClient.close();
                    } catch (IOException e) {
                        log.info("IOException:"+e.getMessage(),e);
                    }
                }
            }
            return null;
        }

        /**
         * 发送delete请求
         *
         * @param url
         * @param token
         * @param jsonStr
         * @return
         * @throws ClientProtocolException
         * @throws IOException
         */
        public static String doDelete(String url, String token, String jsonStr) {

            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpDelete httpDelete = new HttpDelete(url);
            RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
            httpDelete.setConfig(requestConfig);
            httpDelete.setHeader("Content-type", "application/json");
            httpDelete.setHeader("DataEncoding", "UTF-8");
            httpDelete.setHeader("token", token);

            CloseableHttpResponse httpResponse = null;
            try {
                httpResponse = httpClient.execute(httpDelete);
                HttpEntity entity = httpResponse.getEntity();
                String result = EntityUtils.toString(entity);
                return result;
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                if (httpResponse != null) {
                    try {
                        httpResponse.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                if (null != httpClient) {
                    try {
                        httpClient.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return null;
        }
    }

CSRF保护导致的POST请求出现400错误 - PHP解决方案 CSRF(Cross-Site Request Forgery)是一种常见的Web应用程序安全漏洞,攻击者通过伪造用户的身份执行未经授权的操作。为了防止CSRF攻击,常见的做法是在应用程序中实施CSRF保护机制。然而,有时候在启用CSRF保护后,当进行POST请求时可能会出现400错误。本文将介绍可能导致此问题的原因,并提供解决方案。 阅读详情

相关推荐

post 请求报400错误

# !/usr/bin/env python # -*- coding: utf-8 -*- import sys import pycontrol.pycontrol as pc import time import csv import ssl from datetime import date,datetime import urllib2 import urllib import coo...

zhaoyangjian724的专栏 6309

post请求,参数过长导致请求400

背景 近期参与项目,有一个功能在线标注非结构化数据,并把标注内容保存在后台,功能如下: 意外就这样不出意外的出现了,保存请求400 排查 第一阶段 参数key没有对应上吗? 事与愿违,如果这么简单,这篇贴子就不会出现了 第二阶段 在前段调试的时候,有一个参数parmas.wsContent引起了我的怀疑:2M?! 去掉这个参数,请求成功 这个参数截取前50个字符,请求成功 第三阶段 经过第二阶段基本确定是参数过长导致的请求400 网上也确实有说tomcat通过maxPostSize参数

vcakol的博客 1万+

ubuntu安装XXX包时出现(= 20.0.8-0ubuntu1~18.04.1) but it is not going to be installed

安装mujoco_py时,最后一步尝试 import mujoco_py 时出现报错 esashim.c:1:10: fatal error: GL/osmesa.h: No such file or directory 1 | #include <GL/osmesa.h> | ^~~~~~~~~~~~~ compilation terminated. 在https://github.com/openai/mujoco-py#ubuntu-ins

dealexce的博客 1800

post传值单个多个参数 400错误 解决方案

post传值单个多个参数 400错误 解决方案

Mr_chen_zw的博客 3545

OnlyOffice Docker部署实战:解除20连接限制+500M文件上传配置(附中文字体解决方案)

本文详细介绍了OnlyOffice企业级Docker部署的全过程,包括解除20并发连接限制、提升文件上传大小至500MB以及解决中文字体显示问题。通过定制镜像、优化配置和字体安装,帮助技术团队快速搭建高性能的文档协作平台,适用于企业级应用场景。

weixin_26850069的博客 451

解决windows10下无法安装.net framework 3.5(包括.net2.0和3.0)

入域电脑,win10系统中安装 .net framework 3.5(包括.net2.0和3.0)

God_me_1的博客 4万+

ajax从服务器获取图片,JQuery ajax与POST从CORS启用服务器获取图像/ png

我正在编写一个HTML5/Backbone/Phonegap应用程序Github Repo,它使用52n(v1 API Docs)的SensorObservationService REST API。 每个GET-Request都可以正常工作 - 但现在我想要下载POST请求后生成的图片。JQuery ajax与POST从CORS启用服务器获取图像/ png但是服务器与状态400回应:status...

weixin_29218963的博客 550

工控上位机开发学习路线与核心技术解析

工控上位机开发是工业自动化领域的关键技术,通过计算机软件实现对工业设备的监控与控制。其核心在于掌握工业通信协议(如Modbus、OPC UA)、数据处理算法和可视化开发三大能力。上位机系统需要高效解析设备通信协议,处理实时数据,并提供直观的人机交互界面。在智能制造浪潮下,掌握C#语言和工业协议开发能力成为工程师的核心竞争力。典型应用场景包括生产线监控、设备远程运维等。本文基于工业现场实践经验,详解从协议解析到界面优化的全链路开发要点,特别针对Modbus协议调优、WPF性能优化等高频问题提供解决方案。

weixin_30376083的博客 558

记一次.net core调用微信云开发Http Api的uploadFile,上传文件到云环境的坑爹的排错过程

近一年来,想要弄个微信小游戏出来,但是苦于各种原因,总是断断续续,到现在还没有一个拿的出的作品。最近一段时间,看了微信云开发的相关文档,感觉有必要写个类库封装一下云Api,方便以后调用。于是就着手写了一个简单的调用库,过程中基本顺利。直到编写调用云存储,进行文件上传时,遇到了问题。而遍寻百度和谷歌,都没有找到相应的解决办法,所以想着把排错过程记录下来,以方便其他使用.net core 进行微信云开...

czy_csd的专栏 2606

Unity工业数据可视化:基于ModbusTCP的实时数据通信实战

本文详细介绍了在Unity中实现工业数据可视化的核心方法,重点讲解了基于ModbusTCP协议与PLC等工业设备进行实时数据通信的实战流程。内容涵盖NModbus库的集成、Modbus Slave模拟器的使用、TCP连接的建立与多线程安全通信、数据读写与解析,以及如何将实时数据驱动3D场景,为构建工业数字孪生与监控系统提供完整解决方案。

ol7890123的博客 560

为什么idea已经改了UTF-8还是乱码,如何解决?

🏆本文收录于 《全栈Bug调优(实战版)》 专栏,该专栏专注于分享我在真实项目开发中遇到的各类疑难Bug及其深层成因,并系统提供高效、可复现的解决思路和实操方案。无论你是刚入行的新手开发者,还是拥有多年项目经验的资深工程师,本专栏都将为你提供一条系统化、高质量的问题排查与优化路径,助力你加速成长,攻克技术壁垒,迈向技术价值最大化与职业发展的更高峰🚀!

**My Coding Family** 1589

postman请求接口成功,但是前端调用报400

400

思渝崖 8460

Windows 11 WSL2环境下OpenClaw部署的兼容性问题分析与解决方案研究

本文研究了OpenClaw在Windows 11 WSL2环境下的部署方案。WSL2通过无缝集成Linux与Windows系统,为OpenClaw提供了良好的运行环境,支持GPU加速和跨平台开发。文章详细分析了硬件配置要求(推荐8核CPU/16GB内存/NVMe SSD)、系统选择(Windows 11 Pro+Ubuntu 22.04)以及部署步骤,包括WSL2启用、Linux发行版安装、Python/Node.js/Redis等依赖配置。通过优化.wslconfig文件参数(如内存分

博客 2295

前端调用后端接口报400错误,postman成功调用接口

这样,可以提示我们 当后端用到@RequestParam 的时候,我们需要修改请求头中的配置,需要使用headers对象手动设置。通过查找其他博主的资料。可以看到@RequestParam注解和@RequestsBody注解的差别。后端接口中传递的参数前的注释是 @RequestParam,修改前端的 请求头配置。

objectofall的博客 1642

手把手教你学Simulink--移动机器人多轮协同场景实例:基于Simulink的双轮差速PMSM轮毂电机协同驱动仿真

本文介绍了基于Simulink的双轮差速PMSM轮毂电机协同驱动仿真系统。针对移动机器人存在的电机参数不一致、负载分配不均等问题,提出主从同步+力矩补偿的协同控制策略。通过搭建包含运动学模型、PMSM电机模型和矢量控制器的仿真系统,实现了速度同步误差<0.005m/s、轨迹跟踪误差<0.8cm、能耗降低12.5%的优化效果。文章详细阐述了建模步骤、核心算法实现和性能验证,为移动机器人动力系统设计提供了实用参考方案。

MHD0815的博客 141

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Android错误码400,Android Volley POST 请求返回错误 400(错误请求)

我正在尝试使用 Volley Library 使用 JAVA android 应用程序向 Azure IoT Hub 发出 POST 请求,但是我收到此错误:BasicNetwork.performRequest:https://elca-iot.azure-devices.net/devices/elca-main-device/messages/events?api-version=2016-...

weixin_29229261的博客 1141

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

postman测试方法,出现400错误码

下午毛概课上帮同学debug了个错误; postman测试 ,得到返回 400的状态码错误; 查询博客: https://blog.csdn.net/zhangmengleiblog/article/details/52513227 查询400状态码: 400(错误请求) 服务器不理解请求的语法。· 解决方法: 修改请求方式;不适用get 使...

weixin_33672400的博客 7139

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

postmain报400_Postman测试@RequestBody发送请求时报400错误

postman测试@requestbody时碰到400错误图1原因:传参数如果不使用@RequestBody,在使用Postman进行Post请求时,通常做法是填入key和value的值即可。传参数如果使用@RequestBody,在使用@RequestBody注解时,在发送请求时,就需要在Postman的“headers”添加key:Content-Type,value:application/...

weixin_39628271的博客 2335

python的request返回400_python – 在postman的post请求中,flask返回400

我正在lynda做一个烧瓶课程并且遇到了一个例子.https://www.lynda.com/Flask-tutorials/Web-API-Development-Flask/521200-2.html我正在做一个简单的帖子,它可以从基本的webform中运行,但是从邮递员那里失败了.我认为这是因为邮递员对请求编码不同,但无法弄清楚为什么会这样做或为什么烧瓶无法读取它.邮差: 要求在查尔斯截获的...

weixin_40008870的博客 409

httpclient post 总是返回400

最近在使用httpclient模拟shopee电商网站的登陆接口,添加cookie绕过了403错误,无耐又报了400错误。 因为我当时连参数都没有带上,所以心里想的是怎么可能报400错误呢?要报也应该提示我没有带上参数才对啊。 以下是我要模拟的接口图: 因为我在POSTMAN里面content-type使用的是x-www-form-urlencodeed返回的是200,所以我认为http...

窗外小雨 1万+

HTTPS POST请求400错误排查与解决方案

HTTP 400 Bad Request错误是客户端请求存在问题的典型响应,尤其在HTTPS POST请求中更为常见。这类错误通常源于请求格式、内容或配置问题,如JSON格式错误、缺失必填字段或请求头配置不当。排查400错误需要系统性的方法,包括使用Postman、cURL等工具验证请求结构,检查Content-Type设置,以及审查请求体编码。在API开发和调试过程中,理解HTTP协议规范和正确配置SSL/TLS连接至关重要。本文通过典型场景分析,如Content-Type设置错误、SSL/TLS协商失败

weixin_28717969的博客 312

postman能正常请求但java程序请求返回400

问题背景 程序需要调用第三方的接口通过http方式,调用方式及为post请求方式传入json串的格式,通过程序调用后发现是http1.1格式的,然后返回400状态码。以为是参数json有问题,但同样的参数拷贝后拿到postman之行则可以成功。 问题复线 问题代码如下: public static void testHttp(String json){ HttpClient client= new DefaultHttpClient(); HttpPost request = new

mojiewangday的博客 6317

【采坑】axios发送请求报400错误,用postman进行请求测试没问题

目录 原因: 解决方法: 方法一:在前端解决 方法二:在后端解决 原因:请求头错误引起 axios发送的请求头的 Content-Type 默认是 application/json; 而postman默认的是 application/x-www-form-urlencoded 解决方法: 方法一:在前端解决 参考链接:axios发送post请求返回400状态码 使...

weixin_41786574的博客 6390

java 接口 400_java模拟postMan请求OA接口报400错误

**今天在做项目时需要请求一个OA接口,在postMan中可以请求并且访问成功,但是在java代码中,数据是一样的,却报400错误,是不是我的访问方法有问题,还是没有进行浏览器识别,求大神指点一二代码如**下`List>paraMapsList=sqlMap.queryForList("wf_persontask.selectBillTimeOutRemind");List> user...

weixin_39977586的博客 594

postman正常 java403_java模拟postMan请求OA接口报400错误

**今天在做项目时需要请求一个OA接口,在postMan中可以请求并且访问成功,但是在java代码中,数据是一样的,却报400错误,是不是我的访问方法有问题,还是没有进行浏览器识别,求大神指点一二代码如**下`List>paraMapsList=sqlMap.queryForList("wf_persontask.selectBillTimeOutRemind");List> user...

weixin_34033915的博客 1245

java报错400_java模拟postMan请求OA接口报400错误

**今天在做项目时需要请求一个OA接口,在postMan中可以请求并且访问成功,但是在java代码中,数据是一样的,却报400错误,是不是我的访问方法有问题,还是没有进行浏览器识别,求大神指点一二代码如**下`List>paraMapsList=sqlMap.queryForList("wf_persontask.selectBillTimeOutRemind");List> user...

weixin_39633774的博客 644
下一篇: java链接SAP工具类
赚钱买奶茶
博客等级 码龄10年 2粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值