我正在尝试发布一些 xml 以使用 python 以编程方式创建论坛主题。基本上我需要发布带有以下标题的 xml:
授权:基本内容类型:application/atom+xml
这是我尝试使用的代码,但它需要单个 request.post() 中的两个标头:
import base64
from requests.auth import HTTPBasicAuth
import requests
xml = "<xml code here>"
url = 'https://server/forums/atom/forum?id=b7915594-5c46-4ae6-916a-be869aabb327'
userID = 'userid'
password = 'password'
header = {"Content-type": "application/atom+xml"}
r = requests.post(url, headers=header, auth=HTTPBasicAuth(userID,password), data=xml)
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏。提前谢谢您
我使用 Postman(Chrome 应用程序)将 POST 数据发送到 URL,但 PHP 文件永远不会收到 POST 数据,无论我在发送前如何更改内容类型。Apache 上是否有停止从外部来源发布数据的服务器设置?
这是网址:http : //friendesque.com/arranged/handler.php
这是 handler.php 文件的内容:
<?php
echo("Inside file");
echo("JSON:");
$json = file_get_contents('php://input');
echo($json);
echo("POST:");
print_r($_POST);
echo("GET:");
print_r($_GET);
?>
Run Code Online (Sandbox Code Playgroud) 在 Django 视图中,我调用了一个用于上传和导入 excel 文件的函数。
def import_log(request):
report = ""
if request.method == "POST":
file_object = request.FILES
sheet_name = request.POST["sheet_name"]
if len(file_object):
file_object = file_object["file_object"]
if len(file_object):
process_import()
context = {
"report": report
}
return render(request, "import_log.html", context)
else:
return import_upload_view(request, error="No file uploaded")
Run Code Online (Sandbox Code Playgroud)
当我尝试通过单击“停止加载此页面”或关闭浏览器来停止页面时,导入过程不会停止。
这些导入文件非常大,因此我希望能够在需要时从浏览器中终止该进程。
我怎么能做到这一点?
我正在尝试从 Angular 4 应用程序中将传统表单发布到 iframe 中,它只是发布到一个新选项卡中。在我添加ngNoForm到表单元素之前,我根本无法发布表单,所以我假设我需要做其他事情(也许是 iframe 元素?)我的表单标签看起来像:
<form
ngNoForm
method="POST"
action="http://some.url"
target="responseFrame"
>
Run Code Online (Sandbox Code Playgroud)
我的 iframe 标签看起来像:
<iframe id="responseFrame" name="responseFrame" src=""></iframe>
Run Code Online (Sandbox Code Playgroud) 这应该很容易解决,但我知道我的头脑无法找到解决方案。
我有一个这样的帖子:
getAccordo(filtro: Filter): Observable<Response> {
return this.http.post<Response>(`${this.ENDPOINT}/export`,
filtro,
{observe: 'response', responseType: 'blob' as 'json'}
)
.catch(error => this.handleError(error));
}
Run Code Online (Sandbox Code Playgroud)
这就是我使用它的地方:
public getAccordo(event: any): any {debugger;
event.preventDefault();
this.accordiService.getAccordo(this.filter).subscribe(
res => {debugger;
const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const anchor = document.createElement('a');
anchor.href = window.URL.createObjectURL(blob);
anchor.download = Utils.extractHeaders(res);
anchor.click();
},
error => {
console.log(error);
}
);
}
Run Code Online (Sandbox Code Playgroud)
当我查看 chrome 控制台时,我可以看到在标题中有一个 content-disposition: attachment; filename="esportazione_accordi_20180905.xlsx"
但在我的“res”中,这是缺失的。
id 喜欢做的是获取文件名并在anchor.download 中使用它。
感谢您的帮助,如果您需要更多信息,请询问。
编辑
这是我从响应标头中获得的标头,我什至看不到其中的一个:
在服务器端我补充说:.header("Access-Control-Expose-Headers", "content-disposition") 但它仍然不起作用
编辑2:
好的,我们越来越近了,我需要获取图片末尾的“文件名”值并将其分配给anchor.download。
由于轻量级,我使用 vscode 的 REST 客户端扩展而不是 postman,但当我尝试发送 POST 请求时,它似乎没有发送 JSON 数据。它在邮递员和 reqbin 上工作正常,但在 REST 客户端上则不然,我只收到空的正文。
这是请求 URL
@hostname-tour = http://localhost:3000/api/v1/tours
POST {{hostname-tour}} HTTP/1.1
Content-Type: "application/json"
{
"name": "Test Tour",
"duration": "10",
"diffculty": "easy"
}
Run Code Online (Sandbox Code Playgroud)
这是后端代码
const express = require("express");
const app = express();
app.use(express.json());
app.post("/api/v1/tours", (req, res) => {
console.log(req.body);
res.status(200).json({
received: req.body,
});
});
let port = 3000;
app.listen(port, () => {
console.log("Listening at port: ", port);
});
Run Code Online (Sandbox Code Playgroud)
我想要一个带有4个提交按钮的表单。一旦按下它们中的任何一个,它们就会对具有不同内容的同一页面进行外壳调用。为了确定内容是什么,我将编写一个PHP脚本,但到目前为止还没有结束。我的问题是,我需要传递值。
我在这里找到了问题的答案(一种形式有两个提交按钮)。我复制并调整了代码,但无法正常工作。当我想使用定义的名称访问$ _POST数组时,它说这是一个未知索引。到目前为止,这是我的相关代码。
<div>
<form action="nutzerverwaltung.php" method="post">
<input type="submit" class="nv_select" name="nv_select" value="Nutzer hinzufuegen" />
<input type="submit" class="nv_select" name="nv_select" value="Nutzer loeschen" />
<input type="submit" class="nv_select" name="nv_select" value="Nutzer bearbeiten" />
<input type="submit" class="nv_select" name="nv_select" value="Alle Nutzer anzeigen" />
</form>
<br />
</div>
<?php if ($_POST["nv_select"] == "Nutzer hinzufuegen") echo "Hallo"; ?>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么??
约翰
我有这样的代码
<?php
if ( $thismemberinfo[msurf] >= $msurfclicks ) {
$sql=$Db1->query("INSERT INTO d_bonus VALUES('$userid','0.02',NOW())");
echo "success";
} else {
echo "wrong";
}
?>
<form action="" method="post" name="myform">
<input type="hidden" value="123" name="match">
<input type="submit" value="Claim your daily bonus $o.o2" name="submit1">
</form>
Run Code Online (Sandbox Code Playgroud)
我想在用户单击提交按钮后将值保存到数据库中。我一直在尝试不同的方法,但仍然无法接近它。
任何想法/提示我下一步应该做什么或做错了什么?
在下面给出的建议之后是我的代码:
<form action="" method="post" name="myform">
<input type="hidden" value="123" name="match">
<input type="submit" value="Claim your daily bonus $o.o2" name="submit1">
</form>
<?php
if(isset($_REQUEST['submit1']))
{
echo "$thismemberinfo[msurf]";
echo " $msurfclicks";
if ( $thismemberinfo[msurf] >= $msurfclicks ) {
//$sql=$Db1->query("INSERT INTO d_bonus VALUES('$userid','0.02',NOW())");
echo "success"; …Run Code Online (Sandbox Code Playgroud) 我有一个带有 POST 方法的表单。如果我单击提交按钮,它会以 POST 的形式提交,即使我重新加载页面,它也能正常工作,但奇怪的是,当我在地址栏中单击并按 Enter 时,它会以 GET 而不是 POST 形式提交。我无法理解这种行为 浏览器 - Chrome。服务器 - Tomcat 7
提前致谢。