0
It’s giving me an error when I try to make a POST to the API that error is:
System.Net.Webexception: Remote server returned an error: (405) Method not allowed.
The code I’m using is:
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://test-turnoverapi.lyoness.net/");
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/json";
httpWebRequest.Accept = "application/vnd.lyoness.servicesv1 + json";
httpWebRequest.Date = d2;
httpWebRequest.Headers.Add("Authorization", ": " + hashheader);
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
MessageBox.Show("Entrei");
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
MessageBox.Show(json);
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
MessageBox.Show("Entrei");
var teste = streamReader.ReadToEnd();
MessageBox.Show(teste);
}
I would like to know what is the problem with my code and how I can solve it.
Here is an example of a json that the Api provides :
Does the API have a documentation page? you can post?
– Thomas Erich Pimentel
@Thomaserichpimentel can only post an example of a json they have made either ?
– Pedro Azevedo
The more information, the better! but it would be interesting some documentation.. which is the API website?
– Thomas Erich Pimentel
@Thomaserichpimentel already added a print with an example they provide
– Pedro Azevedo
@Perozzo It’s not the same question
– Pedro Azevedo
Maybe it is, since you want to use a REST service in the wrong way. Read the link I put in and check what you’re doing wrong. The recommended object to be used for this type of request is an Httpclient.
– perozzo
HttpClient
is equivalent toWebRequest
– Jéf Bueno
It is equivalent, but whenever I read about it (courses, tutorials, etc.), I recommend using Httpclient and not Webrequest.
– perozzo
@LINQ But this so far was the only way that resulted something all the other forms I tested showed no results
– Pedro Azevedo
Pedro, the problem is the URL you are making the request.
– Jéf Bueno
@LINQ will test another URL that is provided to me then.
– Pedro Azevedo
Your API does not accept post or dua url is wrong. You can use Postmam to better test your API first.
– marcelogribeiro
@LINQ was that very thank you
– Pedro Azevedo