2017-05-24 6 views
-1

Ich bekomme diese WarnungAntrag Methode 'PUT' nicht unterstützt Statuscode: 405

2017-05-25 00:48:43.125 WARN 7104 --- [nio-8080-exec-4] o.s.web.servlet.PageNotFound    : Request method 'PUT' not supported 

in IntelliJ, wenn ich versuche, ein Update von C# (Visual Studio) zu tun. Aber wenn ich dieses Update von Java mache, funktioniert es.

Update-Methode in Java:

@RequestMapping(value = "/{id}", method = RequestMethod.PUT) 
public Proba update(@RequestBody Proba proba) { 
    System.out.println("Updating proba ..."); 
    try{ 
     probaRepository.update(proba.getIdProba(),proba); 
    } catch (Exception e){ 
     e.printStackTrace(); 
    } 
    return proba; 
} 

C# Methode

static async Task<string> UpdateProbaAsync(string path, Proba proba) 
    { 
     string res = null; 
     HttpResponseMessage response = await client.PutAsJsonAsync(path, proba); 
     if (response.IsSuccessStatusCode) 
     { 
      res = await response.Content.ReadAsStringAsync(); 
     } 
     return res; 
    } 

und hier ist, wie ich nenne UpdateProbaAsync

 var rezU = await UpdateProbaAsync("http://localhost:8080/concurs/probe", new Proba(9, "cautare comori UPDATE", "3-5 ani", 0)); 
     var probeUpdate = await GetProbaAsync("http://localhost:8080/concurs/probe"); 
     foreach (var proba in probeUpdate) 
     { 
      Console.WriteLine(proba.ToString()); 
     } 

das ist, was ich für HttpResponseMessage Antwort

+  response {StatusCode: 405, ReasonPhrase: '', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: 
{ 
    Transfer-Encoding: chunked 
    Connection: close 
    Date: Wed, 24 May 2017 21:57:39 GMT 
    Allow: POST 
    Allow: GET 
    Content-Type: application/json; charset=UTF-8 
}} System.Net.Http.HttpResponseMessage 
+0

Ich bin verwirrt über Ihre Anfrage URL '/ pflichtet/auf eine GET-API zu setzen Probe 'vs die Zuordnung von'/{ID} ', vor allem, da Sie nicht einmal die Pfadvariable' ID' für irgendetwas verwenden. Gibt es auch eine '@ RequestMapping' Annotation für die Klasse? – Andreas

+0

Ja, @Andreas '@RestController @RequestMapping ("/concurs/probe ")' –

+0

Kombiniert man die beiden, erhält man '/ concurs/probe/{id}', aber Ihre Anfrage ist nur '/ concurs/probe', Das ist also kein Match. – Andreas

Antwort

0

Ich denke, Sie sind das Attribut aus dem C# fehlt

[HttpPut] //or [HttpPost] 
    [Route("/{path}")] 
async Task<string> UpdateProbaAsync(string path, Proba proba) 
    { 
    } 

Standard-GET ist und Sie versuchen,

Verwandte Themen