我向 AppEngine 服务器发送 POST 请求。HttpServletRequest 说我:
POST /connexionDeconnexion HTTP/1.1
User-Agent: Java/1.6.0_20
Host: localhost:8888
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
Run Code Online (Sandbox Code Playgroud)
我已经发送了世界“HelloHelloHelloHelloHello”,根据Content-Length是正确的。但是,我不知道如何恢复它。你能解释一下吗?
我有一个简单的表单,它接受文本并通过 post 方法调用一个 php 文件 abc.php:
<form method='post' action="abc.php">
<input type="textarea" name="text">
<input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
abc.php 的内容
<?php
$msg=$_POST["text"];
print $msg;
?>
Run Code Online (Sandbox Code Playgroud)
我编写了一个 python 脚本,用于使用请求库发布消息,如下所示:
import requests
keys={'text':'lol rofl'}
r=requests.post("http://127.0.0.1/abc.php/POST",params=keys)
print r.url
print r.text
Run Code Online (Sandbox Code Playgroud)
我得到以下输出(错误):
http://localhost/abc.php/POST?text=lol+rofl
<b>notice</b>:undefined index;text in C:/xampp/htdocs/abc.php on line 2
Run Code Online (Sandbox Code Playgroud)
注意:form 和 abc.php 从浏览器运行时完美运行
我必须确定请求是否来自本地主机。
我在尝试:
要求 http://localhost:3000
# MyController
request.local? # -> 0
request.host # -> localhost
request.ip # -> ::1
request.remote_ip # -> ::1
Run Code Online (Sandbox Code Playgroud)
要求 http://127.0.0.1:3000
# MyController
request.local? # -> 0
request.host # -> 127.0.0.1
request.ip # -> 127.0.0.1
request.remote_ip # -> 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
我想知道是否有标准的方法。看起来像解决方案:ApplicationController.local_request?但受到保护且由于request.local?返回0本地请求而无法正常工作。
我也不能相信,request.host因为它可以被/etc/hosts花招欺骗。
我有一个从问题实体设置的表单生成器:
class Question
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255, name="question")
* @var string $question
*/
protected $question;
/**
* @ORM\Column(type="string", length=255, name="answer1")
* @var string $answer1
*/
protected $answer1;
/**
* @ORM\Column(type="string", length=255, name="answer2")
* @var string $answer2
*/
protected $answer2;
/**
* @ORM\Column(type="string", length=255, name="answer3")
* @var string $answer3
*/
protected $answer3;
/**
* @ORM\Column(type="integer", name="correct_answer")
* @var int $correctAnswer
*/
protected $correctAnswer;
/**
* @ORM\Column(type="datetime", name="post_date")
*/ …Run Code Online (Sandbox Code Playgroud) 您好我正在尝试在nodeJS中使用带有promise的请求模块.
这是我的剧本
require('promise');
var request = require('request');
const requestget = function (url) {
return new Promise((resolve, reject) {
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
resolve(body);
} else {
reject(error);
}
});
});
}
requestget('http://www.modulus.io').then(console.log);
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误.
/home/xyz/reques.js:14
return new Promise((resolve, reject) {
^
SyntaxError: Unexpected token {
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Run Code Online (Sandbox Code Playgroud)
我真的不知道这个剧本有什么不对,任何人都可以帮助我.
这是我的HTML:
<form action='/new' method='POST' >
<span>pool name: </span>
<input type="text" name="name" />
<input type="hidden" name="imageSrcList" />
<button type='submit' >Create new</button>
</form>
Run Code Online (Sandbox Code Playgroud)
这是相关的JS:
var app = express()
app.use(fileUpload());
app.set('view engine', 'ejs')
app.use(express.static(__dirname + '/views'));
Run Code Online (Sandbox Code Playgroud)
app.post('/new', (req, res) => {
console.log(req.body.name);
})
Run Code Online (Sandbox Code Playgroud)
控制台读出:
TypeError: Cannot read property 'name' of undefined
Run Code Online (Sandbox Code Playgroud)
我试过了console.log(req.body),这也是未定义的.
提前致谢!
var formData = {
name: 'TestDeck',
description: 'This is a test deck for my api',
private: false,
shareable: false,
ttsLanguages: [],
blacklistedSideIndices: [],
blacklistedQuestionTypes: [],
gradingModes: [],
imageAttribution: 'https://www.logogarden.com/wp-content/uploads/lg-index/Example-Logo-6.jpg',
imageFile: fs.readFile('retext.png', 'utf8')
}
function createDeck(connection) {
request.post({
url: '<url>',
formData: formData,
headers: {
'Content-Type': 'multipart/form-data'
},
json: true
}),
function(err, resp, body) {
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:TypeError:第一个参数必须是字符串或Buffer。
老实说,我不知道为什么,需要帮助。
当使用NPM请求模块的request.defaults API时,是否有人知道我可以将一个函数作为请求头传递,以便每次发出传出请求时函数的结果都成为头值?
即
request.defaults({
headers:{datestamp:() => new Date()
})
Run Code Online (Sandbox Code Playgroud) 我有以下代码似乎不工作,以防我使用PHP变量来定义值.另一方面,如果我硬编码值,它工作正常.
$body->append('{
"username": "$username",
"password": "$password",
"attributes": {
"name": "$name",
"surname": "$surname",
"email": "$mail"
}
}');
Run Code Online (Sandbox Code Playgroud) 我目前在Django中受POST请求的困扰。我正在尝试从外部应用程序(如智能手机或邮递员(非表格))向其他框架发送POST请求。获取请求就可以了。
我浏览了许多帖子,但无法解决我的问题。我尝试使用request.body,但始终得到一个空响应。我使用print(response.body)将输出打印到控制台上,但只得到b''。
class anyClass(APIView):
def post(self, request):
print(request.body)
return Response({"id": 'anyClass',
"data": '1234',
})
Run Code Online (Sandbox Code Playgroud)
我如何从请求中获取数据?
我与邮递员发送的发帖请求:http : //127.0.0.1 : 8000/ test/ v2/ Api/ anyClass? qrcode= 100023& date= 2018-11-27& time=08:00: 00&value_1=17