我正在尝试使用请求库运行 lambda 函数。我尝试查看其他一些相同的问题,但找不到我需要的问题。以下是我的代码:
var req = require('request');
var headers = { 'X-AUTH-TOKEN': 'xxxx',
'Content-Type': 'application/json',
'Accept': 'application/json'};
var body = {"name" : "omkarEmailTest", "command_type":"SparkCommand", "language":"notebook", "note_id":"56563", "label":"YetAnotherSparkCluster"};
// Configure the request
var options = {
url: 'http://api.quobole.com/api/v1.2/commands',
method: 'POST',
headers: headers,
body: body,
json: true
};
exports.handler = (event, context, callback) => {
req(options, function (error, response, body) {
console.log(body);
callback(error);
});
}
Run Code Online (Sandbox Code Playgroud)
以下是我在 aws lambda 控制台中收到的日志:
Response:
{
"errorMessage": "getaddrinfo ENOTFOUND api.quobole.com api.quobole.com:80",
"errorType": "Error",
"stackTrace": [
"errnoException (dns.js:28:10)", …Run Code Online (Sandbox Code Playgroud) http-post node.js crossdomain-request.js aws-lambda aws-sdk-nodejs
我正在尝试使用 Html2 输入 type="file" 和 angular2 http.post 请求上传文件。当请求到达 web api 时,它失败了
Request.Content.IsMimeMultipartContent()
Run Code Online (Sandbox Code Playgroud)
使用Postman提交请求时不会失败(当我不在标头中包含 Content-Type 时,因为邮递员会处理它)。
请参阅我的代码:Html:
<input type="file" (change)="fileChange($event)" placeholder="Upload file" accept=".pdf,.doc,.docx,.dwg,.jpeg,.jpg">
Run Code Online (Sandbox Code Playgroud)
服务功能:
uploadFile(event) {
let fileUploadUrl = this.webApiFileUploadURL;
let fileList: FileList = event.target.files;
if(fileList.length > 0) {
let file: File = fileList[0];
let formData:FormData = new FormData();
formData.append('uploadFile', file, file.name);
let headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
headers.append('Accept', 'application/json');
let options = new RequestOptions({ headers: headers });
this._http.post(`${this.webApiFileUploadURL}`, formData, options)
.map(res => res.json())
.catch(error => Observable.throw(error)) …Run Code Online (Sandbox Code Playgroud) 我的任务是使用nginx实现微缓存策略,即缓存一些POST端点的响应几秒钟。
在http部分nginx.conf我有以下内容:
proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2 inactive=600s max_size=100m;
Run Code Online (Sandbox Code Playgroud)
然后我location有server:
location /my-url/ {
root dir;
client_max_body_size 50k;
proxy_cache cache;
proxy_cache_valid 10s;
proxy_cache_methods POST;
proxy_cache_key "$request_uri|$request_body";
proxy_ignore_headers Vary;
add_header X-Cached $upstream_cache_status;
proxy_pass http://my-upstream;
}
Run Code Online (Sandbox Code Playgroud)
该应用程序位于输出处,如果我理解正确的my-upstream话Cache-Control: max-age=10,应该使响应可缓存。
但是当我在短时间内(不到10秒)使用curl发出重复请求时
curl -v --data "a=b&c=d" https://my-host/my-url/1573
Run Code Online (Sandbox Code Playgroud)
它们全部到达后端(根据后端日志)。还有,X-Cached总是MISS。
请求和响应如下:
> POST /my-url/1573 HTTP/1.1
> Host: my-host
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 113
> Content-Type: application/x-www-form-urlencoded
>
* upload …Run Code Online (Sandbox Code Playgroud) 我正在使用 django REST 框架创建一个简单的 REST API。我已通过向 api 发送 GET 请求成功获得响应,但由于我想发送 POST 请求,django Rest 框架默认不允许 POST 请求。
如下图所示,仅允许 GET、HEAD、OPTIONS,但不允许 POST 请求

views.py 中的 GET 和 POST 方法
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from profiles_api import serializers
from rest_framework import status
# Create your views here.
class HelloApiView(APIView):
"""Test APIView"""
#Here we are telling django that the serializer class for this apiViewClass is serializer.HelloSerializer class
serializer_class = serializers.HelloSerializer
def get(self, request, format=None):
"""Retruns a list …Run Code Online (Sandbox Code Playgroud) 我有一个通过 http POST 接受图像文件的网络服务,我用 发送它们curl,例如:
curl -X POST -F "image=@ta1.jpeg" -F "image=@ta2.jpeg" http://domain.tld/upload
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 apache bench ( ab) 来测试并发请求。我看到ab可以选择-p发布数据,但我认为这需要 JSON 内容...我尝试使用postmanecho 服务将图像编码为 JSON:
curl -X POST -F "image=@ta1.jpeg" -F "image=@ta2.jpeg" http://www.postman-echo.com/post
Run Code Online (Sandbox Code Playgroud)
将输出保存到文件,并使用 的ab选项发送该文件-p,但会产生服务器错误。
有关如何使用 apache bench 测试 POSTing 图像的任何提示吗?
我目前正在 Python 2.7 中向服务器发出 HTTP Post 请求,requests.post()大约需要 700 毫秒。也绝对没有可能导致延迟的代理服务器,但我仍然绕过任何代理,因为这似乎是该库的问题。
不过我对那一次很好奇,因为在我看来,大约230个字符的答案需要很长时间。这就是为什么我在 Postman 中尝试了相同的请求。结果是Postman中的请求花费了不到100ms!这更适合我要做的任务。一切都与时间有关。
\n\n我想知道是否有任何特定参数requests.post()需要设置,或者这个功能是否那么慢?
目前的请求看起来像这样(非常基本的东西):
\n\nreq = requests.post(url, json={"Username": username, "Password": password, "TerminalNo": terminalno)}) \njson = req.json()\nRun Code Online (Sandbox Code Playgroud)\n\n如果需要,来自服务器的标头:
\n\ncache-control \xe2\x86\x92private\ncontent-length \xe2\x86\x92228\ncontent-type \xe2\x86\x92application/json; charset=utf-8\ndate \xe2\x86\x92Mon, 30 Jul 2018 17:58:05 GMT\nserver \xe2\x86\x92Microsoft-IIS/7.5\nx-aspnet-version \xe2\x86\x922.0.50727\nx-powered-by \xe2\x86\x92ASP.NET\nRun Code Online (Sandbox Code Playgroud)\n 我正在将 exotel 呼叫服务集成到我的一个客户 Android 应用程序中。Api 在邮递员中工作正常并接收 xml 响应,但它在 Android 应用程序中不起作用并给出 volley 401 身份验证错误。
val stringRequest = object : StringRequest(Request.Method.POST,
URL,
Response.Listener { response ->
Toast.makeText(context, "response " + response.toString(), Toast.LENGTH_SHORT).show()
Log.d("Callresponse", response.toString())
}, Response.ErrorListener { error ->
Log.d("Callresponseerror", error.message.toString())
Toast.makeText(context, "error " + error.message, Toast.LENGTH_SHORT).show()
}) {
override fun getParams(): MutableMap<String, String> {
val params = HashMap<String, String>()
params["From"] = AppSetting.getSitterMobile(context, AppConstants.PREF_MOBILE, null)
params["To"] = contact
params["CallerId"] = "*****"
params["CallType"] = "****"
return params
}
}
stringRequest.retryPolicy = DefaultRetryPolicy(10,
10, …Run Code Online (Sandbox Code Playgroud) android http-post http-status-code-401 android-volley exotel-api
我正在 Angular 8 中工作,并在 .net core 2.2 中使用 web.api
我有一个表单,包括一些“常规”输入、一个文件和多个可选复选框。
问题是多选复选框,我将其转换为数字数组。在将数据发布到服务器之前,我将 FormGroup 转换为 FormData 并手动添加文件以及多选复选框中的整数数组:
data.append('locationsSecondaryIds',
new Blob( [ JSON.stringify(this.profilePersonalData.locationsSecondaryIds)], { type : 'application/json' } ) );
if (this.file) {
data.append('document', this.file, this.file.name);
}
Run Code Online (Sandbox Code Playgroud)
locationSecondaryIds 是一个数字[]。
我也尝试过忽略 Blob 并将其作为 [1,1] 发送,但是当服务器到达服务器时,它无法将其转换为列表
有什么好的建议吗?
首先十分感谢 :-)
使用 org.http4s.client 无法找到如何将标头和 UriForm 与 Post 请求一起发送。
import org.http4s.client.dsl.io._
import org.http4s.Method._
val lstHeader: List[Header] = List(
Header("Accept", "application/json")
, Header("Accept-Charset", "utf-8")
, Header("Accept-Encoding", "gzip")
)
val formData :UrlForm = UrlForm(
"username" -> "user",
"enc_password" -> "password",
"queryParams" -> "{}",
"optIntoOneTap" -> "false"
)
val req1 = POST(
formData,
uri"https://www.instagram.com/accounts/login/ajax/"
)
val req2: Request[IO] = Request[IO](
Method.POST,
uri"https://www.instagram.com/accounts/login/ajax/",
HttpVersion.`HTTP/2.0`,
Headers(lstHeader)
)
Run Code Online (Sandbox Code Playgroud)
req1 没有我的标题 req2 没有表单数据
谢谢
我正在使用validate-slack-request包来验证传入的 slack 请求是否来自 slack。这对于斜杠命令和交互组件(按钮等)来说效果很好。但是它不适用于事件 API
我注意到事件 API 的 POST 请求正文具有不同的格式。没有payload. 但我不清楚什么是松弛让我可以用来验证。代码如下
//This WORKS
app.post("/interactiveCommand", async (req, res) => {
const legit = validateSlackRequest(process.env.SLACK_SIGNING_SECRET, req, false);
if (!legit) {
console.log("UNAUTHORIZED ACCESS ", req.headers, req.body);
return res.status(403).send("Unauthorized");
}
await interactiveCommand(...);
return;
});
//This does NOT WORK
app.post("/slackEvents", parser, json, async (req, res) => {
const legit = validateSlackRequest(process.env.SLACK_SIGNING_SECRET, req, false);
if (!legit) {
console.log("UNAUTHORIZED ACCESS ", req.headers, req.body);
res.status(403).send("Unauthorized");
} else {
try {
switch (req.body.event.type) {
case …Run Code Online (Sandbox Code Playgroud) http-post ×10
node.js ×2
android ×1
angular ×1
apachebench ×1
arrays ×1
aws-lambda ×1
c# ×1
caching ×1
django ×1
django-views ×1
exotel-api ×1
express ×1
http ×1
http4s ×1
image ×1
nginx ×1
nginx-cache ×1
post ×1
python ×1
scala ×1
slack-api ×1
typescript ×1