私は、Web APIにJSON経由でオブジェクトを送信しようとしているが、私は私のクライアント側のアクションがあるJSONは、ASP.NETのWeb APIエラーに:(500)の内部サーバーエラー
へと例外実行し続ける:
public string SubmitNewIncident(Incident input)
{
string response = String.Empty;
string serialisedJSON = String.Empty;
input.Type = 0;
serialisedJSON = JsonConvert.SerializeObject(input);
string fpath = String.Format(@"C:\dev\serialisedJSONLog_{0}.txt", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss"));
System.IO.File.WriteAllText(fpath, serialisedJSON);
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
try
{
response = wc.UploadString(new Uri("http://localhost:25657/api/RaiseNew"), serialisedJSON);
}
catch(Exception ex)
{
string path = String.Format(@"C:\dev\ErrorLog_{0}.txt", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss"));
System.IO.File.WriteAllText(path, ex.ToString());
throw ex;
}
}
return (response);
}
JSON文字列は大丈夫ですが、非常に長いです。私のサーバー側のコードは次のとおりです。
public class RaiseNewController : ApiController
{
// GET api/raisenew
[HttpGet]
public HttpStatusCode Get()
{
return HttpStatusCode.OK;
}
//POST api/raisenew
[HttpPost]
public int Post([FromBody] Incident input)
{
input.AssignedTo = AssignNewTicket(input.AppID ?? 0);
return 0;
}
文字列serialisedJSON
の値が長すぎるここ
を投稿する私がアクションを呼び出すと、JSON文字列をアップロードすると、私は次の例外を取得:
System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
を
デシリアライズする前に取得しているテキストと、返される内容を共有してください。あなたがそれを共有することができれば、私はあなたを正しく助けるでしょう。 –
"http:// localhost:25657/api/RaiseNew" ここに拡張子.phpがありませんか? – MwBakker
ASP.NET Web APIはJson.NETを使用します。なぜ廃止予定のJavascriptSerializerを使用していますか?実際には、コンテンツが有効で入力パラメータのタイプを「Incident」に変更した場合、Web APIはオブジェクトを自動的に非直列化します。 –