HTTP 400 Bad Request Error C# -
i'm encountering error: http 400 bad request, possibly error? how check if api correct parameters?
i tried solutions suggested online still no luck. suggest on how resolve issue?
string url = "/api/customers/reconnect/"; //sample url string parameters = new javascriptserializer().serialize(new { accountnumber = info.accountnumber, servicenumber = info.servicenumber, lastname = info.lastname, processtype = info.processtype, reconnectreason = info.reconnectreason, priname = info.priname, requestdate = info.requestdate, amount = info.amount, email = info.email, priname2 = info.priname2, withreconnectfee = info.withreconnectfee, contactno2 = info.contactno2, stmtfaxno = info.stmtfaxno }); httpverb method = httpverb.post; var request = (httpwebrequest)webrequest.create(url); request.method = method.tostring(); request.contentlength = 0; request.contenttype = contenttype; request.accept = "application/json"; var encoding = new utf8encoding(); var bytes = encoding.getbytes(parameters); //encoding.getencoding("iso-8859-1").getbytes(parameters); request.contentlength = bytes.length; using (var writestream = request.getrequeststream()) { writestream.write(bytes, 0, bytes.length); writestream.close(); } using (var response = (httpwebresponse)request.getresponse()) { var responsevalue = string.empty; using (var responsestream = response.getresponsestream()) { if(responsestream != null) using (var reader = new streamreader(responsestream)) { responsevalue = reader.readtoend(); } } if (response.statuscode == httpstatuscode.ok) { var jsonval = jobject.parse(responsevalue); result = (string)jsonval["result"].tostring(); }
whenever see error includes three-digit http status code, means able send request on network , able response. status code provided server, not raised .net runtime or on side. (in cases status code might come device between , server, e.g. load balancer or gateway, not problem.)
to understand error of kind, have understand server. in case left out header server deems mandatory, if have provided of headers required http protocol. server doesn't content of body. server has bug. really... on server.
there no way can troubleshoot problem based on c# client code. need contact folks run service , ask them assistance. may able check logs on side determine why server issued 400 status code. or ask them "known good" request message example (including headers); take , compare own message, looking differences may causing problem.
Comments
Post a Comment