Nasıl terminalden Curl ile JSON veri göndermek için Test etmek için Komut/Bahar DİNLENME?
Ubuntu kullanıyorum ve Curl yüklü. Curl ile Bahar DİNLENME başvurum test etmek istiyorum. Curl ile bunu test etmek istiyorum ancak Java tarafında postama kod yazdım. JSON bir veri post çalışıyorum. Örnek bir veri bu
{"value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true}
Bu komutu kullanın:
curl -i \
-H "Accept: application/json" \
-H "X-HTTP-Method-Override: PUT" \
-X POST -d "value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true \
http://localhost:8080/xx/xxx/xxxx
Bu hata döndürür:
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 1051
Date: Wed, 24 Aug 2011 08:50:17 GMT
Hata Açıklaması Bu
Sunucu istek varlığı bir biçimi istenen yöntem için, istenen sayfa tarafından desteklenmeyen olduğu için bu isteği reddetti ().
Tomcat log: "POST /uı/web/conf/1.1/net HTTP" 415 1051
Komut Curl doğru biçimi hakkında bir fikriniz var mı?
DÜZENLEME:
Bu Java benim yan KOY kod (BUL ve SİL ben denedim ve çalışıyor)
@RequestMapping(method = RequestMethod.PUT)
public Configuration updateConfiguration(HttpServletResponse response, @RequestBody Configuration configuration) { //consider @Valid tag
configuration.setName("PUT worked");
//todo If error occurs response.sendError(HttpServletResponse.SC_NOT_FOUND);
return configuration;
}
CEVAP
-İçerik türü uygulama/json ayarlamanız gerekir. Ama -d
İçerik Türü gönderir Bahar tarafından kabul edilen bir application/x-www-form-urlencoded
,.
** 8, bakarak -H
kullanabilirsiniz
-H "Content-Type: application/json"
Tam örnek:
curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:3000/api/login
Nasıl Http isteği json veri NSURLReque...
komut satırı üzerinden çerez göndermek...
Nasıl birim Temel Veri kullanıyorum şi...
Nasıl CURL ile veri belirtilen POST is...
Nasıl Raylar fonksiyonel test ham post...