ServiceStack HTTP Utils - servicestack

I’ve to make a post request to a service (not implemented with ServiceStack). From the docs, please correct me if I am wrong, I have to use HTTPUtils nuget package (v. 6.0.2), but if I make a request using its extensions the service returns a 400 bad request.
The same request done using RestSharp (v.105.0) works.
However, I noticed that I had to use an old version compared to the available version of RestSharp.(nothing changes if I downgrade ServiceStack).
Could it be that the service implementation is not compatible with the latest versions of RestSharp and ServiceStack?Is it correct to use HTTPUtils for a service that I don't know if it's implemented with ServiceStack?
Does ServiceStack add some extra wrapper to the .NET framework HTTP client?
Thanks in advance

Here are the docs for ServiceStack's HTTP Utils which can be used for calling generic HTTP APIs, which are extension methods in the ServiceStack.Text NuGet package.
Receiving a 400 Bad Request response suggests that you're sending an invalid request.
Whenever you're investigating issues calling HTTP APIs you should be inspecting the HTTP Traffic with a HTTP tool like WireShark or Fiddler so you can verify that it's sending the HTTP Request you want to send, whilst Postman is a useful tool for quickly working out the HTTP Request you want to send.
If you want help with using a tool you'll need to post the C# source code you're using, the HTTP Request/Response it's sending and the HTTP Request you want to send. Typically the HTTP Response should contain information on why your request is invalid.

Related

Is it possible to identify which client sent a HTTP request?

Is it possible to identify the client / library which sent a HTTP request?
I am trying to fetch some data via an API and it is possible to query the API via cURL and python, but when I try to use node (doesn't matter which library, axios requests, unirest, native, ...) or wget I get a proprietary error back from the backend.
Now I am wondering, if the backend is able to identify, which library I am using?
More information:
The requests are exactly the same, so no way to distinguish them
The user-agent header field is set and overwritten for all requests
I already tried to monitor the traffic in wireshark, but couldn't find any differences with the packets on HTTP layer (only the order of the header fields is different, that according to the standard this shouldn't make a difference)
It turns out that the problem was TLS fingerprinting.
See: https://httptoolkit.tech/blog/tls-fingerprinting-node-js/
Nodejs uses google V8 JS engine, V8 based http request clients will not allow you to override headers that would compromise 'web safety', so for example if you are setting "Origin, Host, Referrer" headers, node might refuse to do so. I had the same issue previously.
Un-opinionated http clients, such as the ones written in C++(curl) and python won't 'web safety' check your requests, so that is what is causing the difference in behavior.
In my case I used a C++ library that I called from javascript to make my 'unsafe' requests and the problem was solved.

Is there an Acumatica rest API endpoint that I can use to test if there is a connection

I would like to build an integration using the Acumatica REST API. However, before logging in or anything. I would like to know if there is a way to test that the server is up and running.
I've tried logging in and I looked at the swagger.json to look at all the endpoints but I think they require to be logged in.
I would expect a 200 response when the server is up and a 500 when the server is not. 5XX if there is server issues and an error if it is completely down.
There is no Test function that I know of. I would recommend doing a HTTP GET request on the endpoint URL. If the request succeeds it will return the WSDL schema with 200 success code.

Meteor default http auth

I have a meteor app which makes HTTP calls to some server with basic auth.
Now I want to use a modifier (axios provides interceptors which can modify the requests before sending them) such that on the basis of url, I should be able to add authorization headers.
Eg:
HTTP www.a.com/route1
HTTP www.b.com/route1
HTTP www.a.com/route2
What I want to accomplish is, whenever a request is made to www.a.com, I need to add headers.
I cannot do it manually for each request currently being sent as there are hundereds of requests being sent from different modules of the app.
Already thought of writing a wrapper around meteor's HTTP but any better option like interceptors?

Node.Js : How to log a request's body without access to the Request object

I'm currently using a framework in Node.js ( the botbuilder module from Microsoft Bot Framework) which uses the request[2] module to make HTTP requests.
I'm encountering a problem : this framework seems to send a malformed JSON to Microsoft's servers, but I fail to see why and what is this JSON message made of.
So I'm looking for a way to log those messages, to take a peek at this malformed JSON, as I don't have access to the request object (unless I heavily alter the framework code, which is not something one shall do)
So far, I'm able to log the response body (by adding request to the NODE_DEBUG environment variable), but not the original request body. I did try a tcpdump on our server but since it's all HTTPS there's nothing I can use there.
Any idea / tool that might help ?
Thanks for your time.
Use Node.js middleware to log all your requests. For example, you could use the module request-debug.
Another popular request logging middleware worth knowing about is Morgan, from the Express.js server team.

Sending HTTP request from reactjs/flux to nodejs and sending back HTTP response

Are there are any good simple examples of sending http requests with data from reactjs/flux to nodejs and from the nodejs server sending back an HTTP response with data? I was able to do this in AngularJS with Nodejs since it had a $http service but am confused on how to do this with reactjs. Any help is appreciated.
ReactJS does not come with a http service like you have in AngularJS. That is the way they keep their Library lean.
For making http requests, you can use:
JQuery (Most advised, as its the most used library on the frontend and probably your project or theme is already using it, so no need to include any new library).
Axios, really nice implementation of the Promise API and Client side support for protecting against XSRF (plus supports IE8)
Fetch, built by Github so support is pretty good
Superagent, small, easy to use and easily extensible via plugins

Resources