Send post request to another domain from server - spring

Is there any way in spring where I can POST the requests to another domain from My controller? I have parameters which I need to pass in POST from the controller to another third party domain, is this possible?

What you probably want is for your server to act like a HTTP client and send some data via HTTP POST to a third server:
Your web app client ---> Your web server ---> Another web server
If that is indeed what you need, yes, it is possible. The fact that your application is a web server itself isn't important, although it can be confusing - it's easier to think about it as if you wanted to post the data from an ordinary command-line Java application.
One of the many tools that can help you is Apache HttpClient.

Related

Counterpart of Ajax on server side

I am a beginner in web and server side development and have just read about Ajax. It is used on client side to access any resource over the internet.
But I am thinking of some utility on the server side as ajax so that server is able to send request to the client and client responds to the request.
Do you people know how to achieve this? Basically what I want to achieve is that I have a server which sends the curent server time to the connected client each second.
Thank you!
This can be achieved with websockets.
In .NET we use SignalR to achieve what you need. Server sends a message and client replies to it. This is pubsub scenario.
https://hackernoon.com/create-your-own-pubsub-client-server-use-websocket-65dd1820e997

Can RESTful client enable SSL/TLS *without* "user" authentication?

I am developing an application consisting of RESTful services communicating over HTTP. Spring Boot is providing the underlying support.
As part of my investigations, I am currently working with a known working example of a RESTful client and server that uses HTTPS/SSL/TLS ( https://github.com/indrabasak/spring-tls-example ). I have managed to successfully build, run the example and verify that it works.
Part of the client security configuration code involves setting up basic authorization on a org.springframework.boot.web.client.RestTemplateBuilder.
I am under the impression (perhaps incorrect) that authentication is not required. Am I right or wrong in this assumption?
I have been experimenting with trying to remove the authentication and when I run the example, the server emits output indicating that the action is "Unauthorized". On the client side, I get a 201 response (for a POST), but the JSON data does not contain the data I expect.

Server to server transfer using AJAX

This questions was asked during one of the interview. How to transfer data from one server to another using AJAX? Is it really possible?
AJAX is generally used on the client side, not usually the server side.
It sends requests to a server.
You probably need to provide more information about what you are trying to achieve to get a decent answer.
If you are wanting to transfer data from a "client" to a server then you could send the data in a variety of ways - especially with AJAX. Just how depends on what data type and size. Requests from a client to server (HTTP) can include POST data, which can carry your data to the server.
If you are using AJAX on a client and wanting to use it to transfer data from one remote server to another then you could get AJAX on your client to call a script on the server that would instigate the transfer from the server to another server in some way. (such as FTP or SCP maybe - or even using a server to server HTTP POST)
If you can be a little more specific about what you need to do then I will try and give you a better answer.

Verifiying answers from application to web service and vice versa

Scenario:
My Application stands in connection to Web service (Master Server). Sometimes i make calls like login on application startup, where my application sents user credentials to the master server for validating.
So, how do i 1st validate that the answer is from my real server and not a fake local webserver with routed hosts file? And 2nd how do i parse this answer?
I always parsed like this (dummy code):
if($answerFromWebserver == "LOGIN_OK") {
doLogin();
}
Are there better, more safe solutions?
some of the security feature I see/use,
You can allow specific IPs to server, can setup firewall for this.
Setting up SSL/HTTPS will be great benefit to secure transport level.
You can send username/password encrypted with every message, so at server side authentication will took place each time. You can use SOAP header for this.
You can read huge article from ms here on securing services..

How to register your application into\with Http.sys?

So I created a TCP\HTTP server (IN C#). I want to give to it namespace on my 80's port near to other HTTP servers I have. How to do such thing (step - by step)?
Look at HTTP Server Tasks in MSDN spec:
Initialize HTTP service API, call HttpInitialize
Register URLs with HTTP.SYS, call HttpAddUrlToUrlGroup
Receive a request, call HttpReceiveHttpRequest
Send a response, call HttpSendHttpResponse
Cleanup after urself, call HttpRemoveUrl and HttpTerminate
There is a also a fully fledged application sample at HTTP Server Sample Application.
As you can clearly see, HTTP.SYS API is a C API intended for C applications. You shouldn't be using it from C#, and I'd recommend against pInvoking the entire API. Managed applications have the alternative of using HTTP modules and extend the ASP.Net processing. This avenue will take care of many details needed in a managed server, like activation, hosting, process monitoring and recycling and so on and so forth.
The way you would normally interact with http.sys is by registering an ISAPI DLL with IIS. This is a good starting-point.

Resources