76 questions
1
vote
1
answer
113
views
HttpContent for posting List<ArraySegment<byte>> via HttpClient
I need to post HTTP API requests whose bodies are given as List<ArraySegment<byte>> (the usual fixed header + variable middle + fixed footer stuff). The .NET Socket can send List<...
1
vote
1
answer
1k
views
C# - httpclient - json body - Not getting applied appropriately using httpcontent
The following is the code from where I would return a tuple of response status code and response output.
private Tuple<int, string> API_Check(string URL, string reqtype, string reqbody, string ...
2
votes
1
answer
2k
views
Synchronously acquiring the Response.Content of asynchronous HttpClient.SendAsync, in .NET Standard 2.0
How can I properly extract an HttpResponseMessage Content property (of type HttpContent) in .NET Standard 2.0 plain synchronous manner, acquired after using asynchronous await HttpClient.SendAsync(...
0
votes
1
answer
2k
views
HttpClient headers vs HttpContent headers
In c# why both HttpClient and HttpContent have headers. What is difference between them. When should I use client headers and when content headers ?
CODE EXAMPLE:
HttpClient client = new HttpClient();
...
0
votes
0
answers
549
views
How to write unit test for ReadAsStringAsync
I am trying to write unit tests for the following code:
m_Client.SendAsync(request).ContinueWith(responseTask =>
{
HttpResponseMessage response = responseTask.Result;
try
{
...
0
votes
1
answer
2k
views
Mock HttpClient.SendAsync to return response with Content not null
I'm trying to mock var response = await httpClient.SendAsync(request, CancellationToken.None); but my response.Content is always null.
My mock looks like...
var httpResponseMessage = new ...
0
votes
0
answers
209
views
Problem with Post Request c# got Empty Result
I'm trying to make a simple translator for chinese website using DeepL Traslator, got the data from Live http header
thank in advance --- thank in advance ---- thank in advance
thank in advance --- ...
0
votes
1
answer
1k
views
How to generate Body Parameters/ Sample Request for Web API Help Page while having access to raw request body
I need help populating the Body Parameters for the documentation of this endpoint. It shows as empty:
I realize that the reason this is happening is because I am currently reading the request body and ...
0
votes
1
answer
266
views
C#.NET Web API 2, How can I extract a certain text from a website using the HttpContent on a HTTPGET async method?
I am new to Web and part of my Web API 2 training is to create an API controller that uses an HttpClient and an HttpContent to read entire website and from that to return only a specific portion to a ...
0
votes
1
answer
2k
views
Safely using a StreamReader with HttpContent.ReadAsStreamAsync() without closing the underlying stream
I have multiple Attribute classes which need to access the data in an HttpContent (which is in an HttpActionContext's HttpRequstMessage) but I am having issues deciding on the best way to do it. I ...
2
votes
1
answer
710
views
c# httpcontent - add Header If-Match errors
adding new header "If-Match"
using (HttpContent content = new StringContent(serializedObject))
{
content.Headers.Remove("Content-Type");
content.Headers.Add("Content-...
0
votes
1
answer
1k
views
await vs .Result with HttpContent.ReadAsStringAsync
I have a custom model binder:
public class JsonPolyModelBinder : IModelBinder
{
private readonly JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling....
0
votes
1
answer
5k
views
how to send Content-Disposition: form-data; name="name" in correct way when call post api from C# to avoid statuserror 500
public async Task<T> PostFrom<T>(string baseAddress, string url, string requestbody)
{
T obj = default(T);
//Create the Uri string
string request = baseAddress + url;
...
0
votes
3
answers
6k
views
Can not deserialize HttpContent from POST request
I am trying to send a POST request to a server.The request gets into the Middleware's Invoke method.
However the Content is always null, no matter the type of the object.
Sender
public async Task&...
-1
votes
1
answer
2k
views
POST data using HttpClient
I'm trying to POST a data to web using HttpClient but i can't succeed.
Here is my JSON web api
{
"Categories":[
{
"CategoryID":1,
"Category":"Category 1"
}...
2
votes
3
answers
4k
views
CopyToAsync vs ReadAsStreamAsync for huge request payload
I have to compute hash for huge payload, so I am using streams not to load all request content in memory. The question is what are the differences between this code:
using (var md5 = MD5.Create())
...
-1
votes
1
answer
3k
views
Setting Content type with Default Request Headers
When using HttpClient, I have read examples (such as this example) that uses DefaultRequestHeaders to set the content type (such as "application/json") of a Post request.
I tried to do something like ...
2
votes
1
answer
2k
views
posting a json using httpClient is not arriving at the server
I have this code:
String json = "{\"name\":\"listFiles\"}";
// Wrap our JSON inside a StringContent which then can be used by the HttpClient class
HttpContent httpContent = new StringContent(json, ...
0
votes
0
answers
3k
views
How to call POST method from API using HttpClient?
I am trying to use the HttpClient class to call a POST method from my API which is supposed to add Server information to a DB.
The way I'm trying to call it is below. But when I step through it to ...
0
votes
1
answer
288
views
Xamarin droid challenges when extending HTTPContent
My question is a follow up on: How can I calculate progress with HttpClient PostAsync?
This solution works perfectly. Just remember, if you are using Xamarin, to include the Microsoft.Net.Http nuget ...
2
votes
2
answers
4k
views
How to pass the File Data from C# Console application to WebApi?
I am trying to call the Web api method for saving the File Data.When I debug Webapi method I found that ContentLength is not coming as correct, because of this when i am retrieving the file it is ...
3
votes
1
answer
4k
views
How to POST Json in HttpContent and Parse it in API Controller?
I am wanting to take JSON, put it in a StringContent and pass it to my API. From there, i am wanting to deserialize the JSON back over to a class and use it from there. Currently i am getting an error ...
0
votes
1
answer
90
views
httpclient header + content joined PostAsyn
I am trying to make a PostAsync request with c#. The following is my code.
static void Main(string[] args)
{
CookieContainer cookies = new CookieContainer();
...
2
votes
2
answers
5k
views
How to get HttpContent from Request object?
If a caller adds HttpContent:
using (var content = new MultipartFormDataContent())
{
HttpContent additionalContent = StringContent("just a test");
content.Add(additionalContent);
Which is then ...
0
votes
2
answers
2k
views
HttpResponseMessage.Content.Header ignoring charset setting in meta tag in html source
I have just posted this question, which answer came right away.
It, in turn, creates the following new question:
If my understanding is correct, the StreamContent object, from HttpResponseMessage, is ...