I want to get request a page to set parameters using url(example.com?x=ttt&y=zzz) to reserve those in target server and then should do post request after that final. how can i do these (get request and then post request) in 1 seconds or faster way.
is there any way to do get and post together? but i should get first then post...
Related
JAVA RESTASSURED APITESTNG CUCUMBER
when I send get request using path variable and query param, I get a token in the response body and I will not get proper response until I add that token as a query param and send another get request.
So How can I perform that?
Given Cucumber Feature File
Given API has the following filed <"fieldName">
When API sends a "GET" request to "TranscationAPI"
Then API will receive the response code as 200
And the body will have following field
Should I change it to something like this?
Given API has the following filed <"fieldName">
When API sends a "GET" request to "TranscationAPI"
Then API will receive token as ""
When API sends again "GET" request to "TranscationAPI"
Then API will receive the response code as 200
And the body will have following field
Or I can use handle this through a different method.
Background is the great place to obtain token - see https://cucumber.io/docs/gherkin/reference/#background
It's possible by Java multithreading mechanism - https://www.tutorialspoint.com/java/java_multithreading.htm
Some third party is sending an Http Post request whenever something changes in their DB (e.g. when a contact has been updated, they send the contactID and 'contact_updated'). I have build a socket listener that catches those requests and is able to parse the information. However, I just can't get it to work to send back a response with the status '200 - OK'. Thus, the server on the client side keeps on trying (four times or so) to re-send the request.
Is there any, simple way to just send the response status without the need of adding external libs etc.?
It should be enough to send the string HTTP/1.1 200 OK back in your socket-listener.
If you have troubles, you can check out this answer, it shows how to use a HttpServer in Java just via plain JavaSE features.
Use
response.setStatus(HttpServletResponse.SC_OK);
to set the status code in your response header.
You may also set the content type.
response.setContentType("text/html;charset=UTF-8");
I need to check response header of HTTP request using OkHTTP library. before loading data I need to check it's last update time. The problem in that that the response body is about 2 MB so I need to get only Last-Modified header. Is it possible to load only response header without response body to increase the speed of the program`s RESTful actions?
You can send a HTTP HEAD request which only retrieves the headers. You only need to check if your server application supports HEAD requests.
The HEAD method is identical to GET except that the server MUST NOT
return a message-body in the response. The metainformation contained
in the HTTP headers in response to a HEAD request SHOULD be identical
to the information sent in response to a GET request. This method can
be used for obtaining metainformation about the entity implied by the
request without transferring the entity-body itself. This method is
often used for testing hypertext links for validity, accessibility,
and recent modification. (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html)
Example for OkHttp:
String url = ...
Request request = new Request.Builder().url(url).head().build();
The response body is streamed, so you can make the regular request, read the headers, and then decide whether or not to consume the body. If you don’t want the body, you can close() it without much waste.
There is a slight cost to the server to serve a response that might be abandoned. But the overall cost will be lower than making a HEAD and then a GET request unless you expect abandon a significant fraction (say > 90%) of requests.
I am sending url to another server through response.sendRedirect() method and it is generating pdf for me. I am passing all the parameters but one of the parameter data is exceeding length due to which browser is not able to handle it and request is getting blocked.
I know through Post method we can hide url Parameters and response.sendRedirect() uses GET method. Is there any POST method like sendRedirect through which we can access another server url directly through servlet? Thanks in advance.
With response.sendRedirect(newUrl) you send back a HTTP status 302 with a new Location=newUrl in response header. Thus, you cannot force browser to make POST instead of GET method.
What you could do is to consume a pdf file from within your server code and return it to the client, hiding thus from client the actual target location. You can then build any request with method and parameters you want to the new location if it accept it.
See, for example, this tutorial how to make a request to another server from your servlet http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/
I need to know wheather the parameter is GET or POST but in handle method request.getParameter(name) gives me all parameters. Is it possible to do something like request.getGETParameter(name) and request.getPOSTParameter(name) or do I have to parse raw data myself?
There is no such thing as GET parameters and POST parameters. GET and POST are methods of HTTP request.
You can find out which method your request is by calling
public String getMethod();
on your request.
You might also want to take a look on the description of HTTP protocol http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
The difference between parameters being sent in GET in and POST method is that in GET request parameters are sent in query string, and in POST request these are sent in request body.