How to send PDF to WebService - Asp.NET
I'm having trouble sending a PDF to a Web Service. In the case, the documentation is this way:
So I did the following code:
private async void EnviarDocumentoWhats(string pdf)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://url");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "token");
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("remotejid", "ID"),
new KeyValuePair<string, string>("content", pdf),
new KeyValuePair<string, string>("caption", "valor")
});
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = await client.PostAsync("/message/document", content);
string resultContent = await result.Content.ReadAsStringAsync();
}
}
When running the application I get the following in resultcontent:
"{\"Code\":400,\"Type\":\"error\",\"Message\":\"Document title is empty, or wrong size.\"}\n"
Says the document is empty or wrong size, but I don't know how to solve this issue. Re-checking the documentation I saw is part:
Does anyone know how I can solve this situation? The error as the message itself says is with respect to how this document is being sent, Does anyone have a suggestion or hint of the correct way to send? I appreciate anyone who can help.
Note: the token and ID are working properly, I have already tested sending only messages using another method and it is working.
1