客户端将mjpeg流发布为HTTP POST:
POST /feed/testfeed HTTP/1.0
Content-type: multipart/x-mixed-replace; boundary=--myboundary
--myboundary
Content-length: 14179
Content-type: image/jpeg
....JFIF....
....
Run Code Online (Sandbox Code Playgroud)
我看不到Django中的传入数据.request.read(6)返回空字符串.我添加了假的"content-Length"标题:
POST /feed/testfeed HTTP/1.0
Content-Length: -1
Content-type: multipart/x-mixed-replace; boundary=--myboundary
...
Run Code Online (Sandbox Code Playgroud)
现在它以最大速度读取整个数据.request.read(6)仅在我中断连接后才返回(包含整个数据,而不仅仅是预期的6个字节).
当我使用"PUT"请求而不是"POST"请求时,行为相同.
如何关闭POST请求的缓冲?
我试图在asp.net MVC中传递一个字符串变量.我使用断点,所以我看到它确实转到控制器中的正确方法,但发布的变量等于null.
我的加价:
@{
ViewBag.Title = "TestForm";
}
<h2>TestForm</h2>
@using (Html.BeginForm()) {
<input type="text" id="testinput" />
<input type="submit" value="TestForm" />
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
public ActionResult TestForm()
{
return View();
}
[HttpPost]
public ActionResult TestForm(string testinput)
{
Response.Write("[" + testinput + "]");
return View();
}
Run Code Online (Sandbox Code Playgroud)
我将断点放在第二个TestForm方法中,testinput为null ....我错过了什么吗?
注意:我意识到大部分时间我都会使用模型传递数据,但我想知道我也可以传递字符串.
作为同一问题的一部分,我如何传递几个变量?我的控制器中的方法是这样的:
[HttpPost]
public ActionResult TestForm(string var1, var2)
{
}
Run Code Online (Sandbox Code Playgroud) 我正在研究HttpClientPOST方法.我需要创建HttpClient一次,并且应该使用Keep Alive Connection.但我想在我的情况下,它每次都建立一个新的连接.
所以,我需要使用Keep Alive连接HttpClient.
这是我的代码片段任何帮助将不胜感激.
ClientConnectionManager mgr = httpclient_recv.getConnectionManager();
hp = httpclient_recv.getParams();
httpclient_recv = new DefaultHttpClient(
new ThreadSafeClientConnManager(hp,mgr.getSchemeRegistry()), hp);
while (true) {
try {
java.util.logging.Logger.getLogger("org.apache.http.wire")
.setLevel(java.util.logging.Level.FINER);
java.util.logging.Logger.getLogger("org.apache.http.headers")
.setLevel(java.util.logging.Level.FINER);
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
System.setProperty(
"org.apache.commons.logging.simplelog.showdatetime",
"true");
System.setProperty(
"org.apache.commons.logging.simplelog.log.httpclient.wire",
"debug");
System.setProperty(
"org.apache.commons.logging.simplelog.log.org.apache.http",
"debug");
System.setProperty(
"org.apache.commons.logging.simplelog.log.org.apache.http.headers",
"debug");
ByteArrayEntity bae = new ByteArrayEntity(byteData);
bae.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
"binary/octet-stream"));
httppost_recv.setHeader(HTTP.CONN_DIRECTIVE,HTTP.CONN_KEEP_ALIVE);
httppost_recv.setEntity(bae);
{
System.out.println("res b4 response");
response_recv = httpclient_recv
.execute(httppost_recv);
response_recv.getEntity().consumeContent();
System.out.println("res a4 response");
if (response_recv != null) {
byteArray = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在请求过滤器中获取请求的表单参数:
@Override
public ContainerRequest filter(final ContainerRequest request) {
final Form formParameters = request.getFormParameters();
//logic
return request;
}
Run Code Online (Sandbox Code Playgroud)
但是,表格似乎总是空的.该HttpRequestContext.getFormParameters()文件说:
获取请求实体的表单参数.
此方法将确保缓冲请求实体,以便应用程序可以使用它.
返回: 表单参数,如果有请求实体且内容类型为"application/x-www-form-urlencoded",否则将返回不包含参数的实例.
我的资源是注释的@Consumes("application/x-www-form-urlencoded"),虽然它在请求过滤器之后才会匹配 - 这就是为什么这不起作用?
我尝试做一些研究,但未能找到任何确凿的证据证明这是否可行.有这个为期4年的讨论,Paul Sandoz说:
如果您正在使用泽西过滤器或使用,
HttpRequestContext您可以获得如下表单参数:[到Jersey 1.1.1的断开链接HttpRequestContext.getFormParameters]
我还发现了这个有关如何在请求过滤器中获取multipart/form-data表单字段的3年讨论.在其中,Paul Sandoz使用以下代码:
// Buffer
InputStream in = request.getEntityInputStream();
if (in.getClass() != ByteArrayInputStream.class) {
// Buffer input
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ReaderWriter.writeTo(in, baos);
} catch (IOException ex) {
throw new ContainerException(ex);
}
in = new …Run Code Online (Sandbox Code Playgroud) 我该如何处理输入数组
例如我在我看来:
<input type="text" name="listStrings[0]" /><br />
<input type="text" name="listStrings[1]" /><br />
<input type="text" name="listStrings[2]" /><br />
Run Code Online (Sandbox Code Playgroud)
在我的控制中,我试着获得如下值:
[HttpPost]
public ActionResult testMultiple(string[] listStrings)
{
viewModel.listStrings = listStrings;
return View(viewModel);
}
Run Code Online (Sandbox Code Playgroud)
在调试,我可以看到listStrings的null每一次.
为什么它为null,如何获取输入数组的值
我正在使用API 17模拟器来测试包含Web视图的页面.
我无法在KitKat,Lollipop或Gingerbread上重现同样的问题......到目前为止,我只能在Jellybean和Ice Cream Sandwich上重现这个问题......
我也确认这是运行Jellybean的实际Nexus 7设备的一个问题,因此它不仅仅是一个模拟器问题.
注意:我使用android:configChanges ="orientation | keyboardHidden"之类的东西并不是特别有趣.据我了解,这可能会解决我的轮换问题,但如果由于其他原因需要恢复活动状态,问题仍可能重新出现.
步骤#1:正常加载WebView

步骤#2:提交表单(使用HTTP Post方法)

步骤3:旋转屏幕以触发webview.restoreState - 发生错误

以下是一些与我的问题相关的示例代码.代码在Mono C#中,但应该与Java非常相似.
public class MainActivity : Activity
{
WebView webview;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
webview = new WebView(this);
SetContentView(webview);
if (bundle == null)
webview.LoadUrl("http://2-dot-npwc-services.appspot.com/test-post.jsp");
else
webview.RestoreState(bundle);
}
protected override void OnSaveInstanceState(Bundle bundle)
{
base.OnSaveInstanceState(bundle);
webview.SaveState(bundle);
}
}
Run Code Online (Sandbox Code Playgroud)
执行POST方法的示例HTML页面如下所示:
<html>
<form action="test-post.jsp" method="post">
<input type="text" name="test" value="test"/>
<input type="submit"/>
</form>
<p>You entered: <%=request.getParameter("test")%></p>
</html>
Run Code Online (Sandbox Code Playgroud) 我正在使用一些javascript向/var/www/cgi-bin我的Web服务器上的python脚本发出一个帖子请求,然后在这个python脚本中我想将图像文件保存到我的html文件夹中,以便稍后可以检索它.
位于/var/www/html,但现在我知道如何做到这一点的唯一方法是将python脚本设置为chmod 777,我不想这样做.
那么我怎样才能保存我使用javascript从我的网页抓取的文件,然后通过POST发送到服务器的javascript?
目前当我这样做时,我得到一个错误,说python没有权限保存,因为它的chmod是755.
我这里是python代码,我知道它的工作原理错误就是说我没有权限写这个文件
fh = open("/var/www/html/logo.png", "wb")
fh.write(photo.decode('base64'))
fh.close()
Run Code Online (Sandbox Code Playgroud) 我有一台运行在Google App Engine上的服务器。
我正在通过控制台查看服务器的请求日志。
它们位于下Google Cloud Platform --> Stackdriver Logging --> Logs。
我想查看POST请求的参数。
使用GET-Request很容易,因为它们在条目标题中可见。
在条目的下面,它们也可行protoPayload --> resource。
但是,使用POST请求时,找不到它们。
这是我的选择:
metadataprotoPayloadinsertIdloghttpRequestoperation这些选项似乎都不包含请求的参数。
从这个答案中,我知道它们应该在请求体内。
如何在GAE日志中找到它们?
我有这个基本的帖子请求:
(async () => {
// Create browser instance, and give it a first tab
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
// Allows you to intercept a request; must appear before
// your first page.goto()
await page.setRequestInterception(true);
// Request intercept handler... will be triggered with
// each page.goto() statement
page.on('request', interceptedRequest => {
// Here, is where you change the request method and
// add your post data
var data = {
'method': 'POST',
'postData': …Run Code Online (Sandbox Code Playgroud) 我已经在 CIFAR10 数据集上训练了一个 CNN(占位符,稍后将替换为不同的模型)并将模型集成到烧瓶 API 中。API 托管在 Heroku 上,我现在想使用 Flutter / Dart 在我的手机上拍照,将它们发送到 Flask API,在它们上运行我的训练模型并返回预测。
使用 python,我可以轻松地向我的 API 发出发布请求并返回预测。这是我的简单python代码:
import requests
import json
img = open('some-picture.jpg', 'rb')
files = {'image': img}
response = requests.post("url_to_api", files=files)
print(response.text)
Run Code Online (Sandbox Code Playgroud)
我使用 Flutter / Dart 的时间并不长,我认为发出 htpp 请求的过程比在 python 中复杂一些。有人能给我一些指示或代码,让我可以用我的相机拍照,将它上传到我的 API,并将响应存储在一个变量中吗?这是我的烧瓶 API 的(简化的)python 代码:
from flask import Flask, request
import os
import numpy as np
from PIL import Image
from tensorflow import keras
app = Flask(__name__)
app.config["DEBUG"] = True
model = keras.models.load_model('cifar10_cnn.h5')
labels = ["Airplane", …Run Code Online (Sandbox Code Playgroud) http-post ×10
http ×3
android ×2
asp.net-mvc ×2
java ×2
python ×2
api ×1
arrays ×1
buffering ×1
c# ×1
dart ×1
dio ×1
django ×1
flutter ×1
html ×1
http-request ×1
httpclient ×1
httprequest ×1
javascript ×1
jersey ×1
jersey-1.0 ×1
node.js ×1
php ×1
post ×1
puppeteer ×1
webview ×1