php 使用 Postman 发送 POST 参数不起作用,但发送 GET 参数可以

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24168759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:11:26  来源:igfitidea点击:

Sending POST parameters with Postman doesn't work, but sending GET parameters does

phppostman

提问by whiterook6

I'm trying to test a simple PHP page using the Chrome extension Postman. When I send URL parameters, the script works fine (eg the variables are available in the $_REQUESTparameter). When I send them as x-www-form-urlencodedparameters, the $_REQUESTparameter only contains the PHPSESSID.

我正在尝试使用 Chrome 扩展 Postman 测试一个简单的 PHP 页面。当我发送 URL 参数时,脚本工作正常(例如,变量在$_REQUEST参数中可用)。当我将它们作为x-www-form-urlencoded参数发送时,$_REQUEST参数只包含PHPSESSID.

The script:

剧本:

<?php
var_export($_REQUEST);
?>

When I send URL parameters, $_REQUESTincludes them: URL parameters

当我发送 URL 参数时,$_REQUEST包括它们: 网址参数

But when I send them as POSTvariables, $_REQUESTdoesn't include them: enter image description here

但是当我将它们作为POST变量发送时,$_REQUEST不包括它们: 在此处输入图片说明

What am I missing?

我错过了什么?

回答by Arvind Dhasmana

I faced the same issue in PostMan and Advance REST Client both. I checked through fiddler and found that my request payload is not converted into JSON format.

我在 PostMan 和 Advance REST Client 中都遇到了同样的问题。我通过 fiddler 检查,发现我的请求有效负载未转换为 JSON 格式。

I am passing my data in Body as x-www-form-urlencodedenter image description here

我在 Body 中将我的数据作为x-www-form-urlencoded传递在此处输入图片说明

You can fix it by using Content-Typeas application/x-www-form-urlencodedin request header. enter image description here

您可以通过在请求标头中使用Content-Type作为application/x-www-form-urlencoded来修复它。 在此处输入图片说明

回答by andrewtweber

I was setting the url in Postman to be http://but Apache was redirecting to https://and somehow the POST variables were being dropped along the way.

我在 Postman 中设置了 url,http://但是 Apache 正在重定向到https://并且不知何故 POST 变量在此过程中被删除。

After I changed it to https://, the POST variables worked properly.

在我将其更改为 后https://,POST 变量正常工作。

See also: https://stackoverflow.com/a/28461500/704803

另见:https: //stackoverflow.com/a/28461500/704803

回答by AndroidLearner

Simply use the Body Taband enter the post parametersthere. Note that Body Tabis disabled if Getis selected.

只需使用Body Tab并输入post parameters那里。请注意,Body Tab如果Get选中则禁用。

回答by mushcraft

Check your content-type in the header. I was having issue with this sending raw JSON and my content-type as application/json in the POSTMAN header.

检查标题中的内容类型。我在 POSTMAN 标头中发送原始 JSON 和我的内容类型为 application/json 时遇到问题。

my php was seeing Hyman all in the request post. It wasn't until i change the content-type to application/x-www-form-urlencoded with the JSON in the RAW textarea and its type as JSON, did my PHP app start to see the post data. not what i expected when deal with raw json but its now working for what i need.

我的 php 在请求帖子中看到了 Hyman all。直到我将内容类型更改为 application/x-www-form-urlencoded 并使用 RAW textarea 中的 JSON 并将其类型更改为 JSON,我的 PHP 应用程序才开始查看发布数据。不是我在处理原始 json 时所期望的,但它现在可以满足我的需要。

postman POST request

邮递员 POST 请求

回答by Satish Shinde

When you send parameters by x-www-form-urlencodedthen you need to set header for the request as using Content-Typeas application/x-www-form-urlencoded

当您发送参数时,x-www-form-urlencoded您需要将请求的标头设置为 as using Content-Typeasapplication/x-www-form-urlencoded

回答by John O'Connor

I was having the same problem. To fix it I added the following headers:

我遇到了同样的问题。为了修复它,我添加了以下标题:

Content-Type: application/json

I had to manually add the content type even though I also had the type of "json" in the raw post field parameters.

即使我在原始帖子字段参数中也有“json”类型,我也必须手动添加内容类型。

回答by Lee

Sorry if this is thread Necromancy, but this is still relevant today, especially with how much APIs are used!

抱歉,如果这是线程 Necromancy,但这在今天仍然相关,尤其是在使用了多少 API 的情况下!

An issue I had was: I didn't know that under the 'Key' column you need to put: 'Content-Type'; I thought this was a User Key for when it came back in the request, which it isn't.

我遇到的一个问题是:我不知道在“ Key”列下您需要放置:“ Content-Type”;我认为这是在请求中返回时的用户密钥,但事实并非如此。

So something as simple as that may help you, I think Postman could word that column better, because I didn't even have to read the Documentation when it came to using Fiddler; whereas I did with Postman.

因此,像这样简单的事情可能会对您有所帮助,我认为 Postman 可以更好地说明该专栏,因为在使用 Fiddler 时,我什至不必阅读文档;而我和邮递员做的。

Postman picture

邮递员图片

回答by Choxmi

Instead of using raw JSON body, try using form-data.

与其使用raw JSON body,不如尝试使用form-data

Form data request

表单数据请求

回答by user2229618

For me, the server was expect HTTPS requests, but I didn't specify that in the URL. The hook would reach the server, but the body would be empty.

对我来说,服务器需要 HTTPS 请求,但我没有在 URL 中指定。钩子会到达服务器,但主体是空的。

回答by Mohammed Yasin

Sometimes Version problem in 'Postman' :

I have face the same problem. While sending the data using the oldest version of postman.
That time I have received the empty json data in server side.
And I have fix this problem, Once I uninstall the oldest version of postman and installed with latest version.

有时“邮递员”中的版本问题:

我遇到了同样的问题。使用最旧版本的邮递员发送数据时。
那一次我在服务器端收到了空的json数据。
我有解决这个问题,我曾经卸载邮递员的旧版本,并安装了最新版本。