API Post Bill create work fine but return 405 error
Good day!
I'm developing an application with Embarcadero Delphi, from this application using the component TSslHttpCli package from Overbyte ICS and send a request for creating a new bill.
Send in the json string before that checked me in Postman, and successfully created a new bill. When i send this json string using TSslHttpCli the bill also builds successfully, but the server returns an error 405 "Method not allowed". In the web interface, I see that the bill created. Why error is returned?
Maybe I need to install some additional tuning parameters of the http header? My code:
- //encode national symbol to \uxxx
- function json_encode(str: String): String;
- var
- i: Integer;
- begin
- Result := '';
- for i := 1 to Length(str) do begin
- if Ord(WideString(str[i])[1]) > 127 then begin
- Result := Result + '\u' + Format('%.4x', [Ord(WideString(str[i])[1])]);
- end
- else begin
- Result := Result + str[i];
- end;
- end;
- end;
-
- procedure BeforeHeaderSendPostEvent(Sender: TObject; const Method: String; Headers: TStrings);
- begin
- Headers.Add('Authorization: Zoho-authtoken ' + FAuthToken);
- Headers.Add('Content-type: application/x-www-form-urlencoded');
- end;
-
- SslHttpCli := TSslHttpCli.Create(nil);
- SslHttpCli.OnBeforeHeaderSend := BeforeHeaderSendPostEvent;
- try
- SslHttpCli.Timeout := 12 * 1000;
- SslHttpCli.MultiThreaded := true;
- SslHttpCli.RcvdStream := TMemoryStream.Create;
- SslHttpCli.NoCache := true;
- SslHttpCli.ServerAuth := httpAuthNone;
- SslHttpCli.SslContext := TSslContext.Create(nil);
- SslHttpCli.url := TIdURI.URLEncode(url);
- SslHttpCli.SendStream := TStringStream.Create('JSONString='+json_encode(params));
- try
- SslHttpCli.Post;
- except
- on E: Exception do
- showmessage(e.message); //show returned "Method not allowed"
- end;
-
- if SslHttpCli.StatusCode = 200 then
- begin
- ;// some code
- end
- else
- begin
- showmessage('error code '+inttostr(SslHttpCli.StatusCode));
- end;
JSON string sample:
- '{"vendor_id":"864114000000066015",
- "bill_number":"testbill",
- "date":"2017-09-12",
- "due_date":"2017-09-19",
- "payment_terms":"0",
- "exchange_rate":"0",
- "is_item_level_tax_calc":"false",
- "line_items":[
- {"name":"Test items1",
- "description":"Test items10 description",
- "account_id":"864114000000000370",
- "bcy_rate":"0",
- "rate":"800",
- "quantity":"5",
- "item_total":"0",
- "item_order":"0",
- "is_billable":"false"},
- {"name":"Test items2",
- "description":"Test items20 description",
- "account_id":"864114000000000370",
- "bcy_rate":"0",
- "rate":"16",
- "quantity":"250",
- "item_total":"0",
- "item_order":"0",
- "is_billable":"false"}],
- "taxes":[],
- "notes":"test notes"}'