is there any tool to simulate http requests in jav

2019-07-20 18:55发布

I am trying to simulate HTTP requests in Java with the URL class and the HttpURLConnection class, the GET requests are easy to simulate while some POST requests seem harder because most POST request need Cookie in the request header. Some cookies were set by the HTTP response in the Set-Cookie field and I can get them by the function provided by HttpURLConnection, but I found that other cookies may be set by JavaScript and I have no way to handle them, so I wonder is there any packaged tool to simulate HTTP requests in Java?

3条回答
干净又极端
2楼-- · 2019-07-20 19:17

try Apache commons Httpclient: http://hc.apache.org/httpclient-3.x/

查看更多
Lonely孤独者°
3楼-- · 2019-07-20 19:17

Why do you need to generate HTTP requests? Do you want to perform some stress tests?

I'd advise using something like JMeter (you can find a brief tutorial here).

Hope this helps something, it's better to avoid reinventing the wheel (if you need something like this, but it wasn't clear for me from your question).

查看更多
一纸荒年 Trace。
4楼-- · 2019-07-20 19:27

For the cookie set with Javascript, you could try to parse the HTTP response, extract the cookie information and set it for your next request

For example, lets say, the response has code which calls a setCookie() function (setCookie is user-defined javascript function),

...
//some javascript code
setCookie("username", "johndoe");
//some more javascript
...

then you would extract the line setCookie() and the parse it for the name and value

查看更多
登录 后发表回答