Ben Frisby veya superagent kullanılan hiç, ama burada iki soru vardır bulmak:
yakında istemci tarafında kendisine reddedilecektir, çünkü mümkün değildir
1. passing an invalid JSON from client to server using POST method.
ve sunucuya bir POST isteği yapmadan önce hata alır.
2. pass an invalid JSON just as a string
örnek (http ile çalışırken sadece dizeleri olduğu gibi, müşteri kendisi geçersiz JSON ile sıkışmış alacak JSON stringify çalışacağım çünkü): POST
$.post("demo_test_post.asp",
{
name: 'pqr:{"abc":"abc",}' // see there is a comma at the end making JSON invalid
},
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
JQuery
kullanarak böyle bir dize
Bu, geçersiz JSON'u (bu durumda adı) sunucuya srting olarak etkin bir şekilde iletecektir. Ancak bu, kullanabilmeniz için dizeyi JSON.parse()
kullanarak JSON'a ayrıştırmanızı gerektirecektir. Bunu almak çalıştığımda:
SyntaxError: Unexpected token p at Object.parse (native) at Object.app.get.res.send.data [as handle] (/home/ubuntu/workspace/TapToBook.js:35:19) at next_layer (/home/ubuntu/workspace/node_modules/express/lib/router/route.js:103:13) at Route.dispatch (/home/ubuntu/workspace/node_modules/express/lib/router/route.js:107:5) at proto.handle.c (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:195:24) at Function.proto.process_params (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:251:12) at next (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:189:19) at Layer.staticMiddleware [as handle] (/home/ubuntu/workspace/node_modules/express/node_modules/serve-static/index.js:55:61) at trim_prefix (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:226:17) at proto.handle.c (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:198:9)
Yani istirahatiçin kullanmak paketler hangisi
, bir dize olarak geçersiz JSON geçmesi, ancak bunu kullanamaz.
Kullandığınız dize ve nesnelere örnekler verebilir misiniz? – Demurgos
@Demurgos Bir örnek eklendi, teşekkürler. – alefteris
Bu teste ihtiyacınız varsa, bu hatanın oluşmasını beklediğiniz bir durum olmalıdır. Bu hata oluştuğunda bir senaryo sağlayabilir misiniz? – freele