标签: http-status-code-400

App Engine HTTP状态代码消息

我发现Java dev_appserver和实时App Engine服务器之间存在不一致.

在我的本地开发服务器上,我有一个返回的Servlet:

return response.sendError(response.SC_BAD_REQUEST, "Please log in to comment");
Run Code Online (Sandbox Code Playgroud)

当我访问页面时,我在标题中返回一个状态代码消息:

Status Code:400 Please log in to comment
Run Code Online (Sandbox Code Playgroud)

将此部署到App Engine时出现问题.当访问同一个servlet时,我收到"Bad Request"而不是"Please login in comment":

Status Code:400 Bad Request
Run Code Online (Sandbox Code Playgroud)

Please log in to comment,因为它在开发环境中确实状态代码的消息出现在HTML内容,而不是在头部.

为什么是这样?

编辑

这是curl -vvvvdev_appserver和production 的跟踪:

dev_appserver curl trace:

> POST /add-comment HTTP/1.1
> User-Agent: Mozilla/4.0
> Host: localhost:8080
> Accept: */*
> Content-Length: 9
> Content-Type: application/x-www-form-urlencoded
>         
< HTTP/1.1 400 Please log in to comment
< Content-Type: text/html; charset=iso-8859-1
< …
Run Code Online (Sandbox Code Playgroud)

java google-app-engine http-status-code-400

5
推荐指数
1
解决办法
1274
查看次数

HTTP 400 错误请求 - CURL PHP

我试图发送使用curl PUT请求,但我得到HTTP 400错误的请求,我使用的CURLOPT_VERBOSE调试和与我得到:“错误:恶意请求:期待对象中找到:\”电子邮件\“”}不有人知道这是什么意思/我该如何解决?

代码:

// Set the HTTP headers needed for this API call.

$http_headers = array(
//    "Authorization: Basic xxxxxxxxxxxxxxxxxx",
"Accept: application/json",
"Connection: close",                    // Disable Keep-Alive
"Expect:",                              // Disable "100 Continue" server response
"Content-Type: application/json"        // Content Type json
);

// URL Endpoint of the API to be called.
$ym_api_url = 'https://services.yesmail.com/enterprise/subscribers/718880';
$newsubscriber = array(
'email' => 'karina@email.com',
'firstName' => 'Karina',
'lastName' => 'McG',
'postCode' => 'BT93 EP3',
'prefersMobile' => '',
'emailFormat' …
Run Code Online (Sandbox Code Playgroud)

php api curl http http-status-code-400

5
推荐指数
1
解决办法
2万
查看次数

POST 请求给出 FileNotFoundException

POST 请求给出 URL 的 FileNotFoundException

我正在android中向 Url https://nitos.gr发出 Http POST 请求。

该url没有域名。Stackoverflow 不允许我在文本中包含带有数字的 URL,因此我只是编写一个随机 URL https://nitos.gr来作为示例。

我收到400 响应代码,并打印 getErrorStream() 给出 libcore.net.http.UnknownLengthHttpInputStream@41eba330

但是,我成功执行了 HTTP GET 请求。url 是https,因此我有一个允许所有 SSL 连接的假信任管理器。

总之:

协议: HTTPS

GET请求:成功

POST 请求:失败

请求代码: 400

错误消息: java.io.FileNotFoundException: https: //nitos.gr

错误流: java.io.FileNotFoundException: https: //nitos.gr

执行 POST 请求的方法如下:

public void setTestbedData(String path, String data) {
        HttpURLConnection con = null;

        try {
            con = (HttpURLConnection) ( new URL(Constants.BASE_URL + path)).openConnection();
             // If you invoke …
Run Code Online (Sandbox Code Playgroud)

android filenotfoundexception http-post httpurlconnection http-status-code-400

5
推荐指数
1
解决办法
8001
查看次数

jOOQ:DataAccessException和约束

我正在使用Jersey和jOOQ实现REST API.

我有一个带有一些约束的表,例如一个唯一的键.当插入违反此约束的元组时,jOOQ会抛出DataAccessException:

org.jooq.exception.DataAccessException: SQL [insert into ...]; ERROR: duplicate key value violates unique constraint "issue_name_key"
Run Code Online (Sandbox Code Playgroud)

有没有办法找出违反了哪个约束,没有字符串解析错误消息?如果违反了约束,我想返回一个400 bad requesthttp状态代码而不是一个500 general error.

如果这是不可能的,这里的常见做法是什么?我是否应该查询数据库中每个可能的约束违规?这闻起来像一个维护陷阱.

java http unique-constraint jooq http-status-code-400

5
推荐指数
1
解决办法
1290
查看次数

使用curl在谷歌翻译免费API中出现400错误请求

我正在尝试使用免费的 Google Translate API,它是从 Firefox 的 S3 Google Translator 插件中提取的,即。

\n\n
https://translate.google.com/translate_a/single?client=t&sl=auto&\ntl=en&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t\n&dt=at&ie=UTF-8&oe=UTF-8&otf=2&srcrom=1&ssel=0&tsel=0&q=Hello\n
Run Code Online (Sandbox Code Playgroud)\n\n

在 PHP cURL 中,即。

\n\n
$isPOST=isset($_POST) && !empty($_POST);\n$q=$isPOST ? $_POST['q'] : $_GET['q'];\n\n$url='https://translate.google.com/translate_a/single';\n$data='client=t&sl=auto&tl=en&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&srcrom=1&ssel=0&tsel=0&q='.$q;\n$ch=curl_init();\ncurl_setopt($ch, CURLOPT_HEADER, 0);\ncurl_setopt($ch, CURLOPT_NOBODY, 0);\ncurl_setopt($ch, CURLOPT_URL, !$isPOST ? $url.'?'.$data : $url);\ncurl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);\ncurl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7');\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\ncurl_setopt($ch, CURLOPT_REFERER, $url);\ncurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);\ncurl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);\nif($isPOST){\n    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');\n    curl_setopt($ch, CURLOPT_POST, 1);\n    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);\n}\n$return=curl_exec($ch);\ncurl_close($ch);\n
Run Code Online (Sandbox Code Playgroud)\n\n

我正在使用ajax调用此页面..

\n\n
$.ajax({\n    type: text.length>750 ? 'post' : 'get',\n    url: 'translate.php',\n    data: 'q='+text,\n    success: …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax curl http-status-code-400

5
推荐指数
1
解决办法
4913
查看次数

如何避免ExpressJS引发400错误

背景:我的网站上的Cookie格式错误(来自我的会员页面之一),出现400个错误(空白的400页响应)。我已经编写了删除Cookie的代码,但是我的一些客户仍然收到错误,因为它在其缓存中。一旦他们清除了缓存,问题就解决了。

只需忽略400错误,即可在我的.NET代码库中共同解决此问题,我想在Express JS中也做同样的事情。

问:我想表达对400个错误(通常是由有缺陷的Cookie引起)的所有cookie的忽略,或者至少一起忽略该错误。有什么办法吗?

我的ClearDefectiveCookies函数可供参考(功能正常)

const clearDefectiveCookies = (req, res, next) => {
  const cookies = req.cookies;
  const defectiveCookies = Object.keys(cookies).filter(key => typeof cookies[key] === 'string' && (cookies[key].charAt(0) === '='));

  if (defectiveCookies.length > 0) {
    defectiveCookies.forEach(defectiveCookie => {
      res.clearCookie(defectiveCookie);
    });
  }

  next();
};
Run Code Online (Sandbox Code Playgroud)

有问题的Cookie供参考

名称:xyz_123和值:=NaN=xyz=123

javascript cookies session-cookies express http-status-code-400

5
推荐指数
1
解决办法
143
查看次数

如何确定 tomcat 出现 http 400 错误代码的原因?

我们的一些请求遇到间歇性的 400 响应错误,我试图找出 400 响应的原因。tomcat 的访问日志显示了 400 响应。所以我添加了 tomcat 的 request-dumper 过滤器。查看日志,当 400 发生时,我没有从这个过滤器中得到任何信息。在请求转储程序日志中,日志中记录了在此错误之前和之后立即成功的请求的信息,但没有生成 400 响应的请求的信息。我正在寻找关于什么/如何在 tomcat 中追踪这个问题的建议。我认为请求转储程序会执行此操作,但正如我所说,该日志中没有生成任何内容。

tomcat http-headers http-status-code-400

5
推荐指数
1
解决办法
3156
查看次数

npm 发布:详细堆栈错误:400 错误请求

我使用npm publish返回错误 400 Bad Request,\n我尝试了以下步骤的方法:

\n
    \n
  • delete node_modules
  • \n
  • npm cache clean -f
  • \n
  • npm install
  • \n
  • npm audit
  • \n
\n

但它不起作用。如果您有同样的问题或解决方法\xef\xbc\x8c请告诉我\xef\xbc\x8c谢谢\xef\xbc\x81

\n

我的环境是windows10: v18363.1198 node: v14.15.1 npm: v6.14.9

\n
\n
http fetch PUT 400 https://registry.npmjs.org/byte-download 1400ms\nverbose stack Error: 400 Bad Request - PUT https://registry.npmjs.org/byte-download - Bad Request\nverbose stack     at D:\\Program Files\\nodejs\\node_global\\node_modules\\npm\\node_modules\\npm-registry-fetch\\check-response.js:117:15\nverbose stack     at processTicksAndRejections (internal/process/task_queues.js:93:5)\nverbose statusCode 400\n
Run Code Online (Sandbox Code Playgroud)\n
\n

npm http-status-code-400 npm-publish

5
推荐指数
0
解决办法
2472
查看次数

Twilio 频道 - SMS 60200 无效参数错误(400 错误请求)

我在 Twilio API 中收到“400 - 错误请求”错误,但找不到原因。

这是我的要求:

curl --location --request POST 'https://verify.twilio.com/v2/Services/xxxxxxxxxxxxxx/Verifications' \
--header 'Authorization: Basic xxxxxxxxx' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Channel=sms' \
--data-urlencode 'To=+44xxxxxxxxxx'
Run Code Online (Sandbox Code Playgroud)

我收到回复:

curl --location --request POST 'https://verify.twilio.com/v2/Services/xxxxxxxxxxxxxx/Verifications' \
--header 'Authorization: Basic xxxxxxxxx' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Channel=sms' \
--data-urlencode 'To=+44xxxxxxxxxx'
Run Code Online (Sandbox Code Playgroud)

响应包含RequestID标头,但在 Twilio 门户中无法通过 查找错误RequestID

bad-request http-status-code-400 twilio-api

5
推荐指数
1
解决办法
2900
查看次数

在 Apps 脚本中导入日历事件时如何调试 BadRequest 错误?

我使用了https://developers.google.com/apps-script/samples/automations/vacation-calendar上的“填充团队假期日历”示例来构建一个 Apps 脚本,以将所有外出事件拉入共享日历。该脚本几个月来一直运行良好。如果不对脚本进行任何更改,现在调用时Calendar.Events.import(event, TEAM_CALENDAR_ID);出现错误:

GoogleJsonResponseException:对 calendar.events.import 的 API 调用失败并出现错误:错误请求

我已经在调试器中运行了该脚本,并且该错误并没有提供任何有关错误实际内容的信息,除了 400 错误请求之外。还有很多与日期/时间格式相关的其他问答,但event我导入的变量来自之前的调用,Calendar.Events.list(...)因此它已经是 api 本身生成的 JS 事件对象。

这是一个最小的可重现示例:

let TEAM_CALENDAR_ID = '<calendar id goes here>';

function testImport() {
  const now = new Date();
  let user = Session.getActiveUser();
  
  // Fetch next 10 events
  let events = Calendar.Events.list(user.getEmail(), {
    timeMin: now.toISOString(),
    singleEvents: true,
    orderBy: 'startTime',
    maxResults: 10
  });

  if (events.items.length === 0) {
    console.error('No events found');
    return;
  }

  // Use next upcoming event for this user …
Run Code Online (Sandbox Code Playgroud)

google-calendar-api bad-request google-apps-script http-status-code-400

5
推荐指数
1
解决办法
519
查看次数