is there any tool to simulate http requests in java

邮差的信 提交于 2019-12-24 02:24:12

问题


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?


回答1:


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




回答2:


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).




回答3:


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



来源:https://stackoverflow.com/questions/9250674/is-there-any-tool-to-simulate-http-requests-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!