Service failure Rest

1

I'm trying to perform a put operation on asp.net mvc, but it gives me a bug in:

var response = (HttpWebResponse)httpWebRequest.GetResponse();

This is the bug: {"Error on the remote server: (404) Could not be found."}

Here I leave the code to see if anyone knows why this failure

HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(apiUrl);
httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
httpWebRequest.ContentType = metodo.ContentType;
httpWebRequest.Accept = "application/json";

httpWebRequest.Method = "PUT";
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
string jsonData = jsSerializer.Serialize(datosPUT);
byte[] arrData = Encoding.UTF8.GetBytes(jsonData);
httpWebRequest.ContentLength = arrData.Length;

Stream dataStream = httpWebRequest.GetRequestStream();
dataStream.Write(arrData, 0, arrData.Length);
dataStream.Close ();

var response = (HttpWebResponse)httpWebRequest.GetResponse(); //Fallo
var reader = new StreamReader(response.GetResponseStream());

But nevertheless in another plantarforma test in front of the same server if it works, the bad thing that I do not have access to it

    
asked by Borja Calvo 16.08.2016 в 15:16
source

2 answers

0

In the end the error was that at the end of the URL there was a / and it gave the error 404

    
answered by 06.10.2016 / 16:42
source
0

If you receive this message when consulting your Web Service:

  

{"Error on the remote server: (404) Could not be found."}

I can suggest you review 3 things that usually cause this error:

  • Ensure that you have the correct url of the service defined.

  • Ensure that you define the correct name of the method to consult.

  • Add another option I see that you use the PUT method, is it enabled in the IIS?

  • answered by 17.08.2016 в 12:41