How can you access the response body of System.Net.Http.HttpConnectionResponseContent? - asp.net-core

How can you access the response body of System.Net.Http.HttpConnectionResponseContent?
I'm trying to use the SendGrid API to send an email and it returns an 'HttpConnectionResponseContent' object. How can I acutally get to the response body (string) or JSON? I can't even see how I get hold of the underlying stream.

You can through this to get the content body:
response.Body.ReadAsStringAsync()
You can refer to this.

Related

How to add payload and use the post method to get response from an API in twincat 3?

enter image description hereNot getting appropriate response like I get on the postman application
I tried a few online APIs which give me response, but I need an option to be able to add a payload in my program. I am using tc3 iotbase library from the twincat library repo.
The HTTP POST request payload is builded by the FB_IotHttpRequest function block, when you call one of the send methods
You can use 2 option here:
FB_IotHttpRequest.SendRequest(...) in this case you need to create the payload JSON manually
FB_IotHttpRequest.SendJsonDomRequest(...) in this case you need just pass the reference of the FB_JsonDomParser, which contains the json document.

CDiscount: Problem sending a JSON Get request through Postman

I've been trying to send a GET request to CDiscount's GetProducts API by using the Json format provided by the documentation and have been met with an Error: read ECONNRESET.
I use the Raw (set to JSON) window in Body to send this request.
Any ideas on how to solve this?
GET request doesn't send Body content. Only for POST and PUT send body.

Request for simple parameter in Postman is not working

I am new to Postman. The Get queries work fine but I can't send Post.
I work with Net .Core.
In my controller I have:
[HttpPost]
public IActionResult Post(Order model)
{
return Ok();
}
I am getting error 400 if I am trying to add Content-Type manually or 415 if I leave it as is and just set JSON.
That's because your payload is sent as querystring instead of appliation/json.
The Params becomes querystring in the URL
I didn't see there's a green dot besides the Body. It's likely that you didn't specify a body. In other words, the Body is empty.
It seems that you want to send a payload of application/JSON to server. If that's the case, make sure:
Add a header of Content-Type: application/json in Headers
Add a well-formatted JSON payload in the Body Tab:
By the way,
A controller annotated with [ApiController] expects a payload of application/json by default, which means the clients need send a well-formatted JSON with header of application/json.
However, if you're using a plain controller instead of [ApiController], the body payload by default should be a form. In most cases they'll be application/x-www-form-urlencoded.
PostMan allows us to sends payload of different Content-Types. Please do check the related radio button when there's a need.

Sending GET request parameters in body

I have an API which accepts many parameters.
Passing the values of the parameters will exceed the length of the URL Header.
I am using Postman client to pass the parameters in the body but this is not working any ideas on how to make this work.
The API accepts many parameters because the backend is legacy and is exposed as an API by a service bus.
Older versions of Postman didn't allow you to send body data with get request.
Yet, if your server receives data as URL parameters you won't be able just to change the way of sending them and include them to the body (server won't accept them).
So if the length of parameters is indeed so big and the server indeed can receive the same data from body instead of from parameters then the Postman is just not the tool that you can use (maybe cURL is for you).
If your server allows to send data only as URL parameters and they are so long (more then 2000 chars What is the maximum length of a URL in different browsers?) then I think you have no chances to test this API.
UPDATE: new Version 7.20.1 now allows to send Body with GET request
Workaround:
Change the request type to POST.
Set the value of your body
Change request type to GET
Send request and the body is included
Postman is already added this feature of sending body in get
request.
But i still i recommended to go for post request (if body is present) since many projects like angular http client does't have updated protocols yet.
Latest Postman supports body object for Get request
just choose json format as shown in pic above
If you want to make a GET request in Postman then you can use Params or Body to pass parameters, but not both. Either Params only or Body only. If you specify both Params and Body, Postman will select and send only Params (in GET request of course). So if you want it to send Body, clear Params.

eBay API GetFeedback call returns 'Input data for tag <GetFeedback> is invalid or missing' error

I try to get all feedback (CommentType [positive,neutral,negative], user who left, date, message) for the particular user in xml format. For this I use http request:
https://api.ebay.com/wsapi?callname=GetFeedback&UserID=pashtetgp1988&siteid=0&DetailLevel=ReturnAll&appid=eBayAPID-73f4-45f2-b9a3-c8f6388b38d8&version=511
However, xml output returns error
Input data for tag <GetFeedback> is invalid or missing. Please check API documentation.
Another request with the same appid works fine:
http://open.api.ebay.com/shopping?callname=GetUserProfile&version=537&siteid=0&appid=eBayAPID-73f4-45f2-b9a3-c8f6388b38d8&UserID=pashtetgp1988&IncludeSelector=Details,FeedbackHistory&responseencoding=XML
What can be the problem?
GetFeedback is from of the eBay Trading API Service and you cannot make calls to this service using HTTP GET. The service only supports requests made by HTTP POST. Information required by GetFeedback is passed either through the HTTP headers or the body. The body of the request can be XML or SOAP. More information is available in the eBay documentation.
For future reference you should never expose your appid in code examples.