标签: httprequest

使用 JMeter 以精确的时间间隔发送 HTTP 请求

我正在使用 JMeter 来测试我配置的 Apache2 服务器。我想测试服务器是否可以处理每秒总共出现的 200 个 HTTP 请求,并重复处理很长的秒数(例如 1 分钟,甚至更长)。我阅读了 JMeter 文档,但在理解计时器功能方面有点困难。我配置了测试

 - Numbers of Threads 200
 - Ramp-up period 1
 - Loop Count 100
Run Code Online (Sandbox Code Playgroud)

现在,据我理解和注意到,JMeter的行为是尝试在1秒内提升200个线程,然后尽可能快地执行200*100=20000个请求(或者至少这是我的行为)在我的服务器上遇到),每次 200 个请求块。这意味着服务器可能(实际上确实)每秒接收超过 200 个请求。我想要重现的行为是每秒恰好有 200 个请求。我不在乎它们是否在第二个窗口开始时聚集在一起,或者它们以随机方式出现,分布在第二个窗口中(每 5 毫秒一个,或其他)。所以我尝试了一些定时器,但没有成功。我试过:

  • Constant Timer线程延迟为 5 毫秒。计算一下,它应该每 5 毫秒发送一个请求,并且有 200 个线程,它应该每秒发送 200 个请求 (200*5 = 1000ms)。
  • Constant Throughput Timer目标吞吐量为 12000.0。也许我错了,但这应该是每分钟的样本,所以每 60 秒 200 个请求是 200*20 = 12000(如果样本是一个请求)。我不理解“计算吞吐量基于”选项,我尝试了“仅此线程”(哪一个?)和“所有活动线程”。

无论如何,这些配置都没有达到我的需要。

apache jmeter httprequest

1
推荐指数
1
解决办法
1万
查看次数

如何在QT中同步发送http请求?

以下代码使用 的QTNetwork API 发送 HTTP 请求并获取响应:

void AnotherHttpClient::finished(QNetworkReply *qNetworkReply)
{
    qDebug() << qNetworkReply->readAll();
}

void AnotherHttpClient::get(QString url)
{
    QNetworkAccessManager *man = new QNetworkAccessManager(this);
    connect(man, &QNetworkAccessManager::finished, this, finished);
    const QUrl qurl = QUrl(url);
    QNetworkRequest request(qurl);
    man->get(request);
}
Run Code Online (Sandbox Code Playgroud)

我需要使此代码同步,并且需要 get 方法来返回 qNetworkReply。我该怎么做?顺便问一下,QT 中还有其他同步方式发送 Http 请求吗?

c++ qt httprequest

1
推荐指数
1
解决办法
3903
查看次数

HandleFunc 中的 http 主机和端口信息

我尝试启动多个 http 服务器,侦听同一包中的不同端口。在我的测试 HandleFunc 函数中,我需要打印我们的主机和服务请求的 http 服务器的端口信息。我该怎么做呢?

这是我的示例代码:

package main

import (
    "encoding/json"
    "flag"
    "log"
    "net/http"
    "os"

    "github.com/dineshgowda24/lb/backendserver/config"
)

func main() {
    c := flag.String("c", "config/config.json", "Please specify conf.json")
    flag.Parse()
    file, err := os.Open(*c)
    if err != nil {
        log.Fatal("Unable to open config file")
    }
    defer file.Close()
    decoder := json.NewDecoder(file)
    config := bconfig.BackendConfiguration{}
    err = decoder.Decode(&config)
    if err != nil {
        log.Fatal("Unable to decode conf.json file")
    }
    http.HandleFunc("/", handle)
    for _, s := range config.Servers {
        log.Printf("Started server at : …
Run Code Online (Sandbox Code Playgroud)

httprequest go httpserver go-http

1
推荐指数
1
解决办法
7551
查看次数

如何使用参数 [FromBody] 从 C# 发出 HTTP Patch 请求

我正在创建一个 Web API 服务,但在调用 HTTP 补丁请求时遇到一些问题。尽管我知道如何创建它们。如果您能帮助我,我将不胜感激,这是我的代码:

HTTP 补丁代码:

[HttpPatch("{username}")]
        public async Task<ActionResult> Patch(string username, [FromBody] JsonPatchDocument<User> patchDocument)
        { 
            //If no info has been passed, this API call will return badrequest
            if (patchDocument == null)
                return BadRequest();

            var theUser = await connection.GetAUser(username);
            var originalUser = await connection.GetAUser(username);

            if (theUser == null)
                return NotFound();

            //Changes specified in the patchdocument are applied to the user
            patchDocument.ApplyTo(theUser, ModelState);
            //check if the patching has been successful or not
            bool isValid = TryValidateModel(theUser);

            if (!isValid)
                return …
Run Code Online (Sandbox Code Playgroud)

c# api rest patch httprequest

1
推荐指数
1
解决办法
1万
查看次数

为什么将 RequestUri 作为参数传递与在 HttpRequestMessage 中设置它不同

我有一个 HttpClient (由 IHttpClientFactory 生成),其 BaseAddress 为“www.mydomain.com/3.0/”。我将使用不同的方法使用不同的路径来访问该客户端。所以我首先设置一个 HttpRequestMessage。我注意到这两个实现的行为不同。

这:

var message = new HttpRequestMessage(HttpMethod.Get, $"account-lookup/?query={email}")
{
    Headers =
        {
            { key, value }
        }
};
Run Code Online (Sandbox Code Playgroud)

作品。但是这个:

var message = new HttpRequestMessage()
{
    Method = HttpMethod.Get,
    Headers =
        {
            { key, value }
        },
    RequestUri = new Uri($"account-lookup/?query={email}")
};
Run Code Online (Sandbox Code Playgroud)

返回异常Invalid URI: The format of the URI could not be determined.

我们不能用这样的字符串创建一个新的 Uri,不是吗?为什么我们没有一个属性或方法来让我们传递路径字符串?我假设 HttpRequestMessage 的构造函数在内部将传递的属性附加或连接到 BaseAddress?

我可以/应该做类似的事情
RequestUri = new Uri(Client.BaseAddress + $"account-lookup/?query={email}")
,但是以某种方式附加路径字符串会很好。

c# httpclient httprequest

1
推荐指数
1
解决办法
465
查看次数

SvelteKIt:收到错误“处理程序应该返回响应”,尽管我正在返回一个?

我有一个简单的 API 端点服务器函数,它模仿授权 POST 请求:

/** @type {import('./$types').RequestHandler} */

import { json, error } from '@sveltejs/kit'

export async function POST({ request }) {
    const data = await request.json()

    if (!data.username || !data.password) {
        return error(400, 'Missing username or password.')
    }

    return json({ username: data.username, id: 1 })
}
Run Code Online (Sandbox Code Playgroud)

以及在以下位置使用此函数的表单+page.svelte

async function login() {
        const response = await fetch('/api/auth/login', {
            method: 'POST',
            body: JSON.stringify({
                username,
                password
            })
        })
        const resJSON = await response.json()
        console.log('Form submitted', resJSON)
    }
Run Code Online (Sandbox Code Playgroud)

但我在终端中收到错误:Error: …

httprequest svelte sveltekit

1
推荐指数
1
解决办法
1421
查看次数

无法读取XML数据

我想从远程服务器读取xml文件,但不知何故服务器没有响应我的请求.因此,Gzip抛出"GZip标头中的幻数不正确"异常.任何的想法?

 private static string GetFile()
    {
        Uri uri = new Uri(@"http://www.iddaa.com.tr/XML/IDDAAMACPROGRAMI/index.htm?iddaadrawid=12.09.2012&iddaadrawide=13.09.2012&foraccess=KSsec654");

        string xmlFile;

        HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(uri);
        req.UserAgent =
            "MOZILLA/5.0 (WINDOWS NT 6.1; WOW64) APPLEWEBKIT/537.1 (KHTML, LIKE GECKO) CHROME/21.0.1180.75 SAFARI/537.1";
        req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        req.Headers.Add("Accept-Encoding", "gzip,deflate");


        using (GZipStream zip = new GZipStream(req.GetResponse().GetResponseStream(),
                                               CompressionMode.Decompress))
        {
            var reader = new StreamReader(zip);
            xmlFile = reader.ReadToEnd();
        }

        return xmlFile;
    }
Run Code Online (Sandbox Code Playgroud)

c# gzip webclient httprequest xml-parsing

0
推荐指数
1
解决办法
1906
查看次数

在Node.js请求的响应主体之间获取未定义?

开始学习Node.js,POST用Node.js 发送请求:

var http = require('http')
  , https = require('https')
  , _ = require('underscore')
  , querystring = require('querystring');    

// Client constructor ...

Client.prototype.request = function (options) {
    _.extend(options, {
        hostname: Client.API_ENDPOINT,
        path: Client.API_PATH,
        headers: {
            'user-agent': this.agent
        }
    });

    var req = (this.secure ? https : http).request(options);
    if(options.data) req.write(querystring.stringify(options.data));

    req.end();

    req.on('response', function (res) {
        res.on('data', function (chunk) {
            res.body += chunk;
        });

        res.on('end', function () {
            console.log(res.body);
        });
    });
}
Run Code Online (Sandbox Code Playgroud)

身体表演:undefined<xml version="1.0" encoding="UTF-8">.

哪里undefined来的?

javascript http httprequest node.js

0
推荐指数
1
解决办法
5972
查看次数

获取HTTP请求标头信息:Java

这是我简单的Spring Rest Controller.

每次将URL映射到控制器时,如何获取Http请求标头信息?

@RestController
public class GreetingController {

@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name") String name) {

     // Here is where I want to get HTTP Request Header Info

    return null;     
}
Run Code Online (Sandbox Code Playgroud)

java spring httprequest

0
推荐指数
1
解决办法
999
查看次数

无法将带有[]的索引应用于"HttpRequest"类型的表达式

我试图从我的视图的文本框中获取值.

这是我的观点:

    @model MyDataIndexViewModel

@{
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <h1>Meine Daten</h1>
        </div>
    </div>
    var item = Model.User;
        <div class="row">
            <div class="col-xs-6 col-sm-6 col-md-6 myDataTitle">Email</div>
            <div class="col-xs-6 col-sm-6 col-md-6">
                @Html.TextBox("txtEmail", "", new { placeholder = item.Email})
            </div>
        </div>
}

<div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12">
        <a class="btn btn-default pull-right" href="/ChangeMyData/Save">Speichern</a>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是我的控制器:

   [HttpPost]
    public ActionResult Save()
    {
        var email = Request["txtEmail"].ToString();
        return View();
    }
Run Code Online (Sandbox Code Playgroud)

我得到的错误正如标题中所说的那样.先感谢您!

asp.net-mvc httprequest razor

0
推荐指数
1
解决办法
3404
查看次数