"我需要使用Delphi中IDHTTP的Post方法将JSON对象发送到URL。我尝试直接发送JSON对象字符串以及URL时遇到错误。"
[HttpPost]
public bool SaveTestCases(String testCases)
{
//some codes
return false;
}
the above given is the post URL in the c# with the input string.
I am trying to send the JSON string as input to the URL from the IDHTTP post method.
procedure TfrmTestcases.btnSaveClick(Sender: TObject);
var
http : TIdHTTP;
ReqJson: TStringStream;
data : TIdMultiPartFormDataStream;
begin
http := TIdHTTP.Create(Self);
data := TIdMultiPartFormDataStream.Create;
ReqJson:= TStringStream.Create(DummyArray,TEncoding.UTF8);
//dummyarray contain the Json string {"name":"abcd efgh","ID":"1"}
http.Request.ContentType := 'application/json';
http.Post('https://LocalHost/user/SaveTestCases?testCases='+DummyArray,ReqJson);
end;
"在这里我收到的HTTP 400错误是由于" name"之间的空格造成的。在DummyArray字符串中。有没有其他方式发送JSON object作为上面给出的C#post方法的输入"